Skip to main content
Multiplexing lets you send multiple independent requests over one WebSocket connection. Each logical request gets a client_req_id; the server copies that value onto responses so your client can route audio, text, VAD, and end events back to the right caller. This is useful when you want to avoid opening a new WebSocket for every short utterance or when a server needs to process many low-latency TTS requests in parallel.

How Multiplexing Works

To run requests concurrently on the same socket:
  1. Set close_ws_on_eos: false in every setup.
  2. Generate a unique client_req_id per logical request.
  3. Include that same client_req_id on setup, input messages, and end_of_stream.
  4. Route responses by client_req_id.
If you reuse a client_req_id while the previous request is still active, the server returns a protocol error.

TTS Example

Each audio message contains decoded bytes when using the Python SDK. If you talk to the WebSocket directly, audio is base64 encoded.

Wire Transcript

Client
Server
Responses may arrive interleaved. Do not assume the first request ends before the second one starts returning audio.

STT Notes

The same client_req_id mechanism exists on STT WebSockets. Use it only when each audio source is a separate logical stream and your client can route every audio chunk, flush, and end_of_stream to the right request.
For most live microphone or telephony applications, one STT WebSocket per live speaker stream is easier to reason about. Multiplex STT only when connection overhead matters and you have strict routing tests.

Closing a Reusable Socket

After all logical requests have finished, send an unscoped end_of_stream to close the reusable socket:
If active requests are still running, the server closes after they complete. If no requests are active, it closes immediately.

Error Handling

Errors include client_req_id when the server can identify the logical request:
Treat an error as terminal for that logical request. Depending on the error and whether other sessions are active, the WebSocket may close after outstanding requests finish.

WebSocket Lifecycle

Setup, ready, input, flush, end, and errors.

LLM Tokens to Streaming TTS

Stream generated text while preserving prosody.