Skip to content

Client API

function connect(url: string, options?: ConnectOptions): Promise<ClientSession>;

Opens a connection and resolves once the session is ready. Rejects if the connection closes first or the server refuses it with a non-recoverable error. Browser client describes the options.

MemberTypeMeaning
on(type, listener)() => voidSubscribes to an event; returns an unsubscribe function
interrupt(reason?)voidreason: 'user' (default), 'keyboard' or 'speech'
sendText(text)voidUser text input
setContext(context)voidReplaces the application context; undefined clears it
sendAudio(pcm16)voidOne PCM16 frame in the negotiated input format
close()Promise<void>Closes the session without reconnecting
sessionIdstring | undefinedSet once ready
state'idle' | 'listening' | 'thinking' | 'speaking' | 'acting'The agent’s turn state
epochnumberThe newest epoch seen from the server
connectedbooleanA connection is open and ready
capabilitiesReadonlySet<string>Optional protocol features in effect
EventFieldsWhen
readysessionId, resumedThe session opened, or resumed after a reconnect
statestate, turnId, epochThe agent’s turn changed state
transcriptrole (user or agent), itemId, text, finalSpeech was transcribed; interim updates have final: false
textresponseId, deltaA chunk of the agent’s text response
tool.callcallId, name, arguments, turnId, epochA tool call arrived (whether or not it will run)
tool.streamcallId, name, turnId, epoch, phase, and per phase delta, arguments, progress, ok / code or messageOne step of a call’s lifecycle (tool-stream-v1); one terminal phase unless the session ends first; final close does not synthesize per-call terminals
tool.previewcallId, name, epoch, previewDisplay-only progress of a call (protocol 1.0); never for a closed epoch
tool.resultcallId, name, turnId, epoch, resultA call’s one result
interruptedepoch, source (local or server)epoch and every earlier epoch closed; once per closure
errorcode, message, recoverableFrom the server, or local (AUTH_FAILED, AUDIO_FAILED, RESUME_FAILED)
reconnectingattempt, delayMsThe connection dropped; retrying after delayMs
closedcode?, reason?The session ended and will not reconnect
interface ClientTool {
description?: string;
parameters: JsonSchemaObject; // the arguments, as the model sees them
run(args: any, context: ClientToolContext): unknown;
}
interface ClientToolContext {
signal: AbortSignal; // aborts when the call's turn is interrupted
callId: string;
turnId: string; // the turn that issued the call
epoch: number;
}
type ToolOutcome =
| { ok: true; output: unknown }
| { ok: false; code: 'INTERRUPTED' | 'REJECTED' | 'INVALID' | 'TIMEOUT' | 'FAILED'; message: string };