Establish a connection
Connect to:wss://api.together.ai/v1/audio/speech/websocket
Authentication
- Include your API key as a query parameter:
?api_key=<your_api_key>. - Or use the
Authorizationheader when establishing the WebSocket connection.
Client-to-server messages
Append text to buffer
Commit buffer
Clear buffer
Update session parameters
context_id is specified, all contexts are updated.
Server-to-client messages
Session created
Text received acknowledgment
Audio delta (streaming chunks)
Audio complete
Word timestamps
Sent whenalignment=word is set. Contains word-level timing information for the generated audio.
TTS error
WebSocket example
WebSocket parameters
When establishing a WebSocket connection, you can configure:You can pass these query parameters either in the WebSocket URL (e.g.,
wss://api.together.ai/v1/audio/speech/websocket?model=hexgrad/Kokoro-82M&voice=af_alloy&sample_rate=24000&alignment=word) or dynamically via the tts_session.updated event after the connection is established.Multi-context support
You can manage multiple independent TTS streams over a single WebSocket connection usingcontext_id. This is useful for applications handling multiple simultaneous conversations or characters.
- Add
context_idto any client message to route it to a specific context. - Messages without
context_iduse the"default"context. - Each context maintains its own text buffer and voice settings.
- Cancel a specific context with the
context.cancelmessage type. - Send
tts_session.updatedwithout acontext_idto update all contexts at once. - Maximum 100 contexts per connection.
context.cancelled message:
See also
- Text-to-speech overview for parameters, response formats, voices, and pricing.
- Streaming for HTTP-based streaming and raw byte output.