Realtime sessions

A realtime session is one WebSocket that carries audio in (the user's mic, and optionally meeting audio) and converted speech out, plus JSON control messages and events. The SDK wraps all of this; this page documents the underlying protocol.

Lifecycle

  1. Your server mints a client token (POST /v1/tokens).
  2. The client connects to streamUrl?token=… within expiresIn seconds.
  3. The server sends session.ready with the audio formats.
  4. The client streams audio and sends control messages; the server streams speech and events.
  5. The session ends when either side closes, or at maxMinutes. At 30 seconds before the end you get session.expiring, then session.ended, and the socket closes with code 4001.
  6. Usage is billed from what was actually used. See usage & billing.

Audio

Client → server: binary frames: [channel: 1 byte][PCM16 little-endian, mono, 16 kHz].

ChannelMeaning
1The user's microphone. Converted to the selected voice in voice mode.
2Remote/meeting audio. Heard by the agent in agent mode.

Send 20 ms frames (640 bytes of PCM). Server → client: binary frames of PCM16 LE mono at session.ready.audio.output.sampleRate (24 kHz). Play them in order, without gaps. On a clear event, drop anything buffered.

Control messages (client → server)

typeFieldsEffect
session.updatemode (voice, type, agent), voiceId, language, emotion, speed (0.6–1.5), volume (0.5–2), latency (fast, balanced), agent: { autoReply, bargeIn }Change settings live
saytext, emotion?, interrupt?Speak typed text in any mode
interrupt–Stop all speech immediately
agent.briefbriefing, nameSet the agent's knowledge and persona
agent.whispertextPrivate guidance for the agent's next reply
agent.respond–Make the agent speak now
pingtServer replies pong

voiceId is the voiceId field from GET /v1/voices. The SDK accepts slugs like "leo" and resolves them for you.

Events (server → client)

typeFields
session.readysid, expiresAt, audio, agentEnabled, catalog, state
session.updatedstate
transcriptchannel (mic, remote), text, final
speech.start / speech.endid, source (voice, text, agent), text
clearreason (interrupt, barge_in)
agent.thinking, agent.text, agent.said, agent.suggestion, agent.silentSee agent
usageconnectedSec, micSec, remoteSec, ttsChars (every 15 s)
session.expiring / session.endedsecondsLeft / reason
errorcode, message

Latency

  • Typed lines: first audio in about 0.3–0.6 s.
  • Live voice: in fast latency mode, words are spoken as soon as the live transcript is stable, often before the speaker finishes the sentence. Expect about 0.5–1.2 s end-to-end.
  • balanced waits for finalized phrases: slightly slower, fewer corrections.

Emotion

emotion accepts: neutral, happy, excited, calm, confident, content, sad, angry, scared, surprised, sarcastic, sympathetic, tired, curious, anxious, disappointed, frustrated, apologetic, flirtatious, mysterious. Each emotion also applies a delivery profile (pace and loudness), so it's audible even on short lines. Emotion is strongest on voices tagged expressive.