Quick start
/access-token endpoint. See Authenticate client applications for token handling.
Connect
X-API-Key header. Browser and mobile applications should send an access_token query parameter. Never expose an API key in a client application.
The connection captures the agent’s current version when it opens. A configuration change does not affect a call already in progress. The session_ready event reports the resolved agent_version_id and the call’s call_id.
Start the session
Sendsession_create as the first event, within 10 seconds of connecting:
mulaw_8000, pcm_16000, pcm_24000, and pcm_44100. Agent audio uses the same format.
output_delivery defaults to speaking_pace. Use as_available when your application manages its own playback buffer. as_available cannot be used when the agent has background audio configured.
Wait for session_ready before sending audio:
Stream audio
Send user audio as base64-encodedaudio_input events. Chunks of 20 to 100 milliseconds usually provide good latency.
audio_output events in the configured format:
audio_output_clear. Discard buffered agent audio and stop playback immediately. The event can arrive while no agent audio is playing, in which case there is nothing to clear.
Conversation events
Useturn_started, turn_output_text_delta, and turn_ended to show speaking state or build a transcript. Assistant text arrives incrementally in turn_output_text_delta; turn_ended.text contains the final text for either role.
These events are informational. Audio handling should not depend on them.
Client tools
When the agent invokes a client tool, the server sendsclient_tool_call:
expects_response is true, answer with the same tool_call_id:
Errors and connection limits
The server sends anerror event when it rejects an event. A recoverable error has fatal: false; a fatal error is followed by a connection close.
- A JSON message may be up to 32 KiB. Larger messages close with code
1009. - The server closes after 120 seconds without a valid client event. Streaming audio continuously, including silence, keeps the connection active. WebSocket ping frames do not reset this application-level timer.
- Close with code
1000for a normal client shutdown. The server uses1008for protocol errors and1011for internal failures.