Skip to main content
The headless entry has no UI dependency and is safe to import on a server. Constructing a client opens no connection. Calling start() or sending the first message can initiate network requests and a connection.

Client options

ChatClientOptions accepts required agentId, optional baseUrl (default https://api.osvi.ai), and optional auth (anonymous by default). It also accepts fetch, WebSocketImpl, store, page, and random hooks for custom environments and controlled integrations. Server mode accepts a getToken callback from your backend; see Logged-in users.

State

Subscribers receive a ChatState snapshot. Its fields include connection status (idle, connecting, open, recovering, offline, or closed), conversation mode (ai or human), awaitingReply, transcript items, activeInteraction, interactionPending, agent, and error. The agent value is null until anonymous bootstrap succeeds, or, in server mode, until the session opens; it is then set from the session snapshot. Use getState() for a synchronous current snapshot. subscribe(listener) returns an unsubscribe function. A state item is a message, an interaction, a divider, or a welcome item (the agent’s welcome message).

Methods and outcomes

send() resolves with { ok: true, messageId } when the client has queued/transmitted the message locally, or { ok: false, reason } for empty, destroyed, awaiting_interaction, or unavailable. ok: true is not confirmation of server delivery. Watch the transcript item status: sending is local, and sent reflects server confirmation. The client retries or reconciles transport-level busy/unknown outcomes; a failed transcript item can be retried with its existing idempotency key.

Errors

state.error holds the current error, with a stable code, a message, a retryable flag and, for an origin rejection, the rejected origin. Every code, with what it means and what to do, is in Error codes.