- 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.
Server warnings
The server can report problems with a session’s setup that it otherwise works around silently. Ask for them by settinglog_level in setup:
ready, the server then sends one log message per problem:
log_levelis"debug","info","warning"or"error": the lowest level to receive. Any other value fails setup validation.- Without
log_level, the server sends nologmessage. - Make sure your client accepts or skips the
logmessage type before you enable it. - Some models do not report warnings yet. For them,
log_levelis accepted and nologmessage is sent. - The SDKs support it from Python
gradium0.6.5, JavaScript@gradium/sdk0.2.0 and the Rustgradiumcrate 0.1.17.
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.