Skip to main content
Realtime is for voice agents and anything conversational. One session is one WebSocket. You send text as it is produced and get audio back as fast as the engine makes it. Each turn of speech runs in a context, and a session can run several contexts at once.
Two contexts on one WebSocket session: text goes out as task_start and task_continue; audio comes back per context; cancelling a context drops the audio still in flight

Say something

Stream text from an LLM

Send text a token or a sentence at a time, then finish() the turn:

Interruptions (barge-in)

When the user starts talking, cancel the turn. Audio still on its way for that context is dropped, and iterating the context ends with a cancelled event.

Events

Iterating a context yields, in order: A turn that fails throws RealtimeError (for example with code voice_not_found).

Limits and reconnects

  • A session runs up to 4 contexts at once, and holds one of your plan’s concurrent-synthesis slots until it closes. Opening one more than the plan allows throws RateLimitError with code concurrency_limited (wait retryAfter seconds), so reuse a session.
  • If the connection drops, running contexts throw RealtimeError. Check its retryable flag. The next context reconnects automatically; turn this off with connect({ autoReconnect: false }).
  • Running out of credits ends the session with a RealtimeError whose code is insufficient_credits.
  • Text is billed per character as it is sent. A session reserves credits in blocks of up to 1,000 characters and returns what it doesn’t use when it ends.
To use realtime from a browser or device, connect with a short-lived token. The wire protocol behind the SDK is described in Realtime WebSocket.