- Connect with authentication.
- Send a
setupmessage. - Wait for, or lazily receive,
ready. - Send input messages (
textfor TTS,audiofor STT). - Optionally flush buffered input.
- Send
end_of_stream. - Read output until the server sends
end_of_streamorerror.
Endpoints
Authentication
Server-side clients should send the API key in thex-api-key header:
?token=...; see
Browser WebSockets.
Setup
The first logical message for every request issetup.
TTS setup
STT setup
TTS-specific setup fields:
STT-specific setup fields:
Ready
After setup, the server sendsready. You can wait for this before
sending input, or start sending immediately and let the SDK capture it
while receiving.
TTS ready
STT ready
request_id in logs and support tickets. For STT, use
delay_in_frames when tuning turn-taking or forced flush behavior.
Input
TTS accepts text messages:Flush
TTS supports model-level flushing with the<flush> tag inside text:
flush message:
End
Sendend_of_stream when you are done sending input for a request:
close_ws_on_eos: false in setup and keep sending new setup/input
groups.
Multiplexing
To run multiple logical requests over one socket:- Set
close_ws_on_eos: false. - Attach a unique
client_req_idto every message for a request. - Route every response by its matching
client_req_id.
Errors
WebSocket errors are sent as JSON and then the socket closes:error as terminal for that socket. Open a new connection when
retrying. Common codes:
For REST and WebSocket error contracts, see Errors.
Next steps
Text-to-Speech WebSocket
Stream text in and receive audio chunks back.
Speech-to-Text WebSocket
Stream audio in and receive text, VAD, and flush events.
Multiplexing
Run several logical requests on one WebSocket.
Browser WebSockets
Use short-lived tokens without exposing API keys.