Skip to main content
wscat -c "wss://api.gradium.ai/api/speech/tts" \
  -H "x-api-key: YOUR_API_KEY"
wscat -c "wss://api.gradium.ai/api/speech/tts" \
  -H "x-api-key: YOUR_API_KEY"

Lifecycle

{"type":"setup","voice_id":"YTpq7expH9539ERJ","model_name":"default","output_format":"pcm"}
{"type":"text","text":"Hello, world."}
{"type":"end_of_stream"}
The server responds with ready, then one or more audio and text messages, and finally end_of_stream. See WebSocket Lifecycle for connection behavior, reusable sockets, browser tokens, and errors.

Client Messages

setup

FieldTypeRequiredDescription
typestringYesAlways "setup".
model_namestringNoModel alias, defaults to "default".
voice_idstringRecommendedVoice library or custom voice ID.
voicestringNoVoice name fallback when voice_id is not provided.
output_formatstringNowav, pcm, opus, ulaw_8000, alaw_8000, or explicit PCM rates such as pcm_16000. Defaults to wav.
json_configobject or stringNoAdvanced TTS settings. See Voice Settings.
pronunciation_idstringNoPronunciation dictionary ID.
client_req_idstringNoCorrelates multiplexed requests.
close_ws_on_eosbooleanNoDefaults to true; set false to keep the socket open.
retry_for_snumberNoOptional setup retry window in seconds.

text

FieldTypeRequiredDescription
typestringYesAlways "text".
textstringYesText chunk to synthesize.
client_req_idstringNoRequired when routing a multiplexed request.

end_of_stream

FieldTypeRequiredDescription
typestringYesAlways "end_of_stream".
client_req_idstringNoEnd the matching multiplexed request.

Server Messages

ready

FieldTypeDescription
typestringAlways "ready".
request_idstringGradium request ID for logging and support.
model_namestringRequested model alias.
model_extstringResolved model identifier, when present.
sample_rateintegerOutput sample rate.
frame_sizeintegerOutput frame size in samples.
audio_stream_namesstring[]Named audio streams, when present.
text_stream_namesstring[]Named text streams, when present.
client_req_idstringPresent for multiplexed requests.

audio

FieldTypeDescription
typestringAlways "audio".
audiostringBase64-encoded audio chunk.
start_snumberChunk start time in seconds.
stop_snumberChunk stop time in seconds.
stream_idintegerStream identifier, when present.
client_req_idstringPresent for multiplexed requests.

text

FieldTypeDescription
typestringAlways "text".
textstringText segment associated with generated audio.
start_snumberSegment start time in seconds.
stop_snumberSegment stop time in seconds.
stream_idintegerStream identifier, when present.
client_req_idstringPresent for multiplexed requests.

Terminal messages

TypeDescription
end_of_streamThe request is complete.
flushedReserved for flush acknowledgements.
errorTerminal error message; the socket closes after the error.
Error
{"type":"error","message":"Error description","code":1008}

Headers

x-api-key
string
required

Your Gradium API key

Response

101

WebSocket connection established