Skip to content

Client SDK Overview

Copy page

@divinci-ai/client is a headless, browser-compatible SDK. It gives you chat threads, token-by-token streaming, realtime WebSockets, and per-user RAG — and leaves the UI entirely to you. Use it to build a chat experience in React, Vue, Svelte, or vanilla JS.

  • Thread-based chat with streaming and non-streaming sends
  • Realtime updates over auto-reconnecting WebSockets
  • Rich, typed error hierarchy (Error Handling)
  • Pluggable token storage and three identity models (Authentication)
  • A wide namespace surface — RAG, audio, notifications, API keys, arena, and more
  • First-class TypeScript types from @divinci-ai/types
Terminal window
npm install @divinci-ai/client

The client is thread-oriented: create (or reuse) a thread, then send messages into it.

import { DivinciClient } from "@divinci-ai/client";
const client = new DivinciClient({
releaseId: "rel_your-release-id",
userToken: jwtFromYourBackend, // or apiKey + externalUser — see Authentication
});
const thread = await client.chat.create();
const response = await client.chat.send(thread.id, "Hello!");
console.log(response.message.content);
OptionTypeDefaultDescription
releaseIdstringRequired. The Release the chat runs against.
apiKeystringAPI key (pair with externalUser outside a browser).
userTokenstringShort-lived user access token (see Authentication); wrapped in a SimpleTokenStorage.
externalUserExternalUserConfigEnd-user identity for attribution.
tokenStorageTokenStorageCustom token persistence + refresh.
originstringBrowser origin sent to /embed/validate-login during automatic token refresh (v0.5.0+). Must be in the API key’s allowedOrigins. Required for setRefreshToken() auto-refresh.
workspaceIdstringDefault workspace for namespace calls.
baseUrlstringhttps://api.divinci.appAPI origin.
wsBaseUrlstringwss://live.divinci.appWebSocket origin.
streamingbooleantrueDefault streaming behavior.
timeoutnumber30000Request timeout (ms).
maxRetriesnumber3Automatic retries for transient failures.
apiVersionstringAPI version header (X-API-Version); sent only when set.
headersRecord<string,string>Extra headers on every request.
debugbooleanfalseVerbose logging.

Beyond the namespaces, the DivinciClient instance exposes:

MethodDescription
getRelease() / refreshRelease()Fetch (or re-fetch) the Release config.
setToken(token, expiresAt?)Store a user token.
setRefreshToken(token)Store an /embed/login refresh token. With origin configured, the client exchanges it via /embed/validate-login for a fresh access token automatically on 401 (v0.5.0+).
logout()Clear stored tokens.
isAuthenticated()Whether a usable token is present.
validateApiKey()Verify the configured API key.
setExternalUser(user)Set/replace the external-user identity.
withWorkspace(id)Return a client scoped to a workspace.
getConfig() / getHttpClient()Escape hatches for advanced use.

The client groups operations into lazily-initialized namespaces:

chat, homepageChat, anonymousChat, freeChatGate, siteControl, terms, rag, arena, websocket, audio, user, apiKeys, byok, stylePattern, fineTune, notifications, analytics, metrics, and feedback.

The most common ones are covered in their own pages; the rest are summarized in Namespaces.