Handshake
The first message on the WebSocket — client to server — must be a handshake. The server replies with handshake_ack and the conversation can begin.
Client → server: handshake
{
"type": "handshake",
"content_type": "json",
"content": {
"conversationId": "optional — resume an existing conversation",
"conversationType": "text" | "audio",
"audioConfiguration": {
"input": { "format": "...", "sampleRate": ..., "frameDurationMs": ... },
"output": { "format": "...", "sampleRate": ..., "frameDurationMs": ... }
},
"capabilities": ["local_tools_discover"]
}
}
| Field | Required | Type | Notes |
|---|---|---|---|
conversationId | no | string | If you pass one and it exists for this agent, the conversation is resumed. Otherwise a new one is created. See Reconnect. |
conversationType | no | "text" | "audio" | Defaults to "text". |
audioConfiguration | no | object | Optional for voice (defaults to PCM/8000/8000 if omitted). Ignored for text. |
capabilities | no | string array | Optional list of optional client capabilities the server may use. The only value the server consumes today is "local_tools_discover" — see Local tool discovery below. |
audioConfiguration shape
audioConfiguration has input and output blocks with the same fields:
| Field | Type | Allowed values | Required |
|---|---|---|---|
format | string | "audio/lpcm", "audio/opus", "audio/pcmu", "audio/pcma" | optional — input defaults to "audio/lpcm", and output defaults to whatever input resolved to. |
sampleRate | number | 8000 (default), 16000. G.711 accepts 8000 only. | optional |
frameDurationMs | number | 20, 40, 60 | required when that side's format is "audio/opus" — input and output are validated independently. Accepted but ignored for every other format, so a device may send it unconditionally. |
"audio/pcmu" is ITU-T G.711 µ-law and "audio/pcma" is A-law: 8-bit
companded mono at 8 kHz, one byte per sample. They cost almost no CPU or memory to encode
compared with Opus, at the price of a fixed 64 kbit/s — the right trade for a constrained
device on a reliable link, the wrong one for a bandwidth-limited connection.
Examples:
// Default voice config (PCM 8 kHz)
"audioConfiguration": {
"input": { "format": "audio/lpcm", "sampleRate": 8000 },
"output": { "format": "audio/lpcm", "sampleRate": 8000 }
}
// Opus, 16 kHz, 20 ms frames — common for low-bandwidth devices
"audioConfiguration": {
"input": { "format": "audio/opus", "sampleRate": 16000, "frameDurationMs": 20 },
"output": { "format": "audio/opus", "sampleRate": 16000, "frameDurationMs": 20 }
}
// G.711 µ-law up, Opus down — minimises encode cost on the device while keeping
// downlink bandwidth low. The two directions are configured independently.
"audioConfiguration": {
"input": { "format": "audio/pcmu", "sampleRate": 8000 },
"output": { "format": "audio/opus", "sampleRate": 16000, "frameDurationMs": 20 }
}
Server → client: handshake_ack
{
"type": "handshake_ack",
"content_type": "json",
"content": {
"conversationId": "cnv_abcdef...",
"status": "created" | "resumed"
},
"metadata": {
"model_id": "anthropic:claude-sonnet-5-5"
}
}
| Field | Type | Notes |
|---|---|---|
content.conversationId | string | The active conversation ID. Save this for resuming later. |
content.status | "created" | "resumed" | Whether you got a fresh conversation or picked up an existing one. |
metadata.model_id | string | Which LLM the agent is using for this turn. |
After the handshake_ack, you can start sending user messages (text mode) or audio_stream_start + binary audio (voice mode).
Bad handshakes
If the server rejects your handshake, you'll see an error envelope followed by a close. Handshake-time errors use the structured error shape — content_type: "json", with code / message / details inside content.
content.code | Cause |
|---|---|
| (no envelope code) | First message wasn't a handshake. The server emits a generic error and closes. |
INVALID_AUDIO_FORMAT | audioConfiguration.input.format or .output.format is not one of "audio/lpcm", "audio/opus", "audio/pcmu", "audio/pcma". The message names the offending side. |
INVALID_AUDIO_SAMPLE_RATE | audioConfiguration.input.sampleRate or .output.sampleRate is not 8000 or 16000, or is not 8000 for a G.711 format. The message names the offending side. |
INVALID_FRAME_DURATION_MS | Opus chosen on input or output, but the matching side's frameDurationMs is missing or not 20/40/60. The message names the offending side. |
QUOTA_EXCEEDED | The user has exceeded their daily quota. content also includes current_usage, limit, remaining, percentage. |
See Errors & Lifecycle for the full list and the two error envelope shapes.
Examples
Minimal text handshake
{
"type": "handshake",
"content_type": "json",
"content": { "conversationType": "text" }
}
Resume an existing conversation
{
"type": "handshake",
"content_type": "json",
"content": {
"conversationType": "text",
"conversationId": "cnv_abc123"
}
}
Voice with PCM at 8 kHz
{
"type": "handshake",
"content_type": "json",
"content": {
"conversationType": "audio",
"audioConfiguration": {
"input": { "format": "audio/lpcm", "sampleRate": 8000 },
"output": { "format": "audio/lpcm", "sampleRate": 8000 }
}
}
}