Endpoint
Authenticating
The WebSocket accepts your API key either as a header or as a query parameter (useful for browser clients that can’t set headers on a WebSocket handshake):chariotai-api-key header where your client allows it. If authentication fails, the server accepts the socket, sends an error frame, and closes with code 1008.
Connection parameters
Pass these as query parameters on the connection URL:UUID of the voice to synthesize with.
Audio encoding of the binary frames. One of
pcm (raw signed 16-bit LE PCM) or wav (streaming WAV, a RIFF header followed by PCM).How incoming text is chunked into synthesis units. One of
sentence, clause, or none.Seconds the server waits for a client message before closing the session as idle. Must be greater than 0 and at most 300.
When
true, each generated segment is archived to your TTS history and the audio is stored for later retrieval.Message protocol
All control messages are JSON text frames. Audio is delivered as binary frames.Client → server
Append text to synthesize. The server buffers and splits it according to
split_granularity.Force the server to synthesize whatever text is buffered right now, without ending the session.
Signal that no more text is coming. The server flushes the remainder and finishes the session.
Server → client
A new sentence is about to stream. Carries the
sentence_index, the sentence_text being spoken, the format, and sample_rate (when known).One or more binary frames of audio for the current sentence, in the negotiated
response_format.The current sentence has finished streaming. Includes
total_bytes and credits_utilized (the credits charged for this sentence).All sentences are complete. The server will close the connection normally (
1000).An error occurred. Carries a
message and, for terminal errors, a code matching the close code.Audio format
response_format | Frames contain |
|---|---|
pcm (default) | Raw signed 16-bit little-endian PCM, mono. Sample rate from audio.start.sample_rate (44100 Hz by default). |
wav | A streaming WAV: a RIFF header followed by the same PCM. |
Close codes
The connection closes with one of these codes. The close reason carries a short human-readable message.| Code | Meaning |
|---|---|
1000 | Normal, the session completed successfully. |
1008 | Policy violation, authentication failed, an invalid parameter, the voice is not ready, or the idle timeout fired. |
1011 | Internal error, the upstream synthesis service was unavailable. |
4402 | Insufficient credits, the workspace ran out of credits mid-session. |
Billing
Billing on the WebSocket is per sentence, charged when each sentence finishes (audio.done), at 1 credit per character of the synthesized sentence. The per-sentence cost is reported in the credits_utilized field of each audio.done.
If the workspace runs out of credits mid-session, the sentence currently in flight is delivered (a one-sentence grace), then the server sends an error frame with code 4402 and closes. You are not charged for the ungrantable sentence.
Limits
| Limit | Value |
|---|---|
| Idle timeout | Configurable, default 60 s, maximum 300 s |
| Session length | No fixed cap on total text, send input.text as needed |
| Per-sentence input | Governed by split_granularity |
Example
Python
Send
input.text as soon as each fragment of text is available, you don’t need to wait for a full sentence. The server assembles sentences and streams audio for each as it becomes complete.