Skip to content

Setup Guide

This guide covers everything you need to go from zero to a working Imbrace SDK integration — installation, credentials, environments, and service URL overrides.


System Requirements

RequirementMinimum version
Node.js18.0.0+
npm8.0.0+
Python3.9+
pip23.0+

Installation

From npm registry:

Terminal window
npm install @imbrace/sdk
# or
yarn add @imbrace/sdk
# or
pnpm add @imbrace/sdk

Monorepo / local development:

Terminal window
# Step 1 — install dependencies and build
cd ts
npm install
npm run build
# Step 2 (optional) — link globally to use in another project on the same machine
npm link

Then in your external project:

Terminal window
npm link @imbrace/sdk

Verify:

import { ImbraceClient } from "@imbrace/sdk";
console.log("SDK loaded:", typeof ImbraceClient); // 'function'

Configure Credentials

Create a .env file

The SDK does not auto-read environment variables — you pass credentials directly to the constructor. A .env file is a user convention for storing secrets; use dotenv or your framework’s env loader to read them.

# Credentials
IMBRACE_API_KEY=your_api_key_here
IMBRACE_ACCESS_TOKEN=your_jwt_token_here
# Organization ID — sent with every request
IMBRACE_ORGANIZATION_ID=your_org_id_here
# Optional: override the gateway URL directly
IMBRACE_BASE_URL=https://app-gatewayv2.imbrace.co

Get an API Key

Option 1 — Imbrace Portal: log in and go to Settings → API Keys.

Option 2 — via API (requires an existing access token):

Terminal window
curl -X POST https://app-gatewayv2.imbrace.co/private/backend/v1/third_party_token \
-H "x-access-token: <your_existing_token>" \
-H "Content-Type: application/json" \
-d '{"expirationDays": 30}'

The value you need is response.apiKey.apiKey.


Environments

NameGateway URLUse when
develophttps://app-gateway.dev.imbrace.coInternal development
sandboxhttps://app-gateway.sandbox.imbrace.coIntegration testing
stablehttps://app-gatewayv2.imbrace.coProduction (default)

Switch environments via the env constructor option, or override the URL directly with baseUrl:

const client = new ImbraceClient({ env: "sandbox" });

Initialize the Client

import { ImbraceClient } from "@imbrace/sdk";
// Server-side — API Key
const client = new ImbraceClient({
apiKey: process.env.IMBRACE_API_KEY,
organizationId: process.env.IMBRACE_ORGANIZATION_ID,
baseUrl: "https://app-gatewayv2.imbrace.co", // or use env: "stable"
});
// Client-side — Access Token (e.g. after OTP login)
const client = new ImbraceClient({
accessToken: process.env.IMBRACE_ACCESS_TOKEN,
baseUrl: "https://app-gatewayv2.imbrace.co",
});
// OTP login flow
const anon = new ImbraceClient({ baseUrl: "https://app-gatewayv2.imbrace.co" });
await anon.requestOtp("user@example.com");
await anon.loginWithOtp("user@example.com", "123456");
// Token is stored automatically on the client

Quick Usage Examples

import { ImbraceClient } from '@imbrace/sdk'
const client = new ImbraceClient({ apiKey: process.env.IMBRACE_API_KEY })
// Get current user
const me = await client.platform.getMe()
// List channels
const channels = await client.channel.listChannels()
// Send a message
await client.channel.sendMessage('conv_123', { content: 'Hello!', type: 'text' })
// AI completion
const result = await client.ai.complete({
model: 'gpt-4o',
messages: [{ role: 'user', content: 'Summarize this.' }],
})
// AI streaming
for await (const chunk of client.ai.stream({ model: 'gpt-4o', messages: [...] })) {
process.stdout.write(chunk.choices[0]?.delta?.content ?? '')
}
// AI Agent — streaming chat
const response = await client.aiAgent.streamChat({
id: 'chat_id',
assistant_id: 'asst_abc',
organization_id: 'org_abc',
messages: [{ role: 'user', content: 'Hello' }],
})

Override Service URLs

Use this when a microservice runs at a different address (e.g. local dev, dedicated staging).

const client = new ImbraceClient({
env: "develop",
services: {
aiAgent: "http://localhost:4000/ai-agent",
dataBoard: "http://localhost:3001/data-board",
channelService: "http://localhost:3002/channel-service",
},
});

All valid service keys:

Python keyTypeScript keyService
gatewaygatewayApp Gateway
platformplatformPlatform service
channel_servicechannelServiceChannel service
data_boarddataBoardData Board
backendbackendBoard/Items backend (/v1/backend)
ipsipsIPS service
aiaiAI service
marketplacesmarketplacesMarketplace service
file_servicefileServiceFile service
message_suggestionmessageSuggestionMessage Suggestion service
predictpredictPredict service
activepiecesactivepiecesActivePieces
ai_agentaiAgentAI Agent service

Troubleshooting

Cannot find package '@imbrace/sdk'

Package is not linked. Re-run from ts:

Terminal window
npm link
cd /path/to/your-project && npm link @imbrace/sdk
ERR_MODULE_NOT_FOUND for files in dist/

Package has not been built yet:

Terminal window
cd ts && npm run build
ModuleNotFoundError: No module named 'imbrace'
Terminal window
cd py && pip install -e ".[dev]"
401 Unauthorized

API Key expired or invalid. Generate a new one:

Terminal window
curl -X POST https://app-gatewayv2.imbrace.co/private/backend/v1/third_party_token \
-H "x-access-token: <your_existing_token>" \
-H "Content-Type: application/json" \
-d '{"expirationDays": 30}'
UserWarning: ImbraceClient: no credentials provided

No api_key or access_token passed. If intentional (e.g. login-only flow), ignore this warning. Otherwise check your .env file.