Other clients
/v1/audio/speech
Speech over HTTP, shaped like OpenAI's audio/speech: the OpenAI SDK works with the base URL and key changed.
Request#
POST /v1/audio/speech on the speech host with your router API key as Authorization: Bearer tcr_…. Audio streams back as each sentence is ready: from your org’s cache when it has been synthesized before, otherwise from the provider, with the key stored for your org.
import osfrom openai import OpenAIclient = OpenAI( base_url="https://api.media.ttscacherouter.dev/v1", api_key=os.environ["TTS_CACHE_ROUTER_API_KEY"],)with client.audio.speech.with_streaming_response.create( model="sarvam/bulbul:v3", voice="shubh", input="नमस्ते, मैं सिटी हॉस्पिटल से प्रिया बोल रही हूँ।", response_format="mp3", extra_body={"language": "hi-IN"},) as response: response.stream_to_file("speech.mp3")curl https://api.media.ttscacherouter.dev/v1/audio/speech \ -H "Authorization: Bearer $TTS_CACHE_ROUTER_API_KEY" \ -H "Content-Type: application/json" \ -d '{"model": "raya/standard", "voice": "d6a002d0-230c-49b1-a137-b8a7d564b1ae", "language": "hi", "input": "नमस्ते, मैं प्रिया बोल रही हूँ।", "response_format": "wav"}' \ --output speech.wavFields the OpenAI SDK doesn’t have go in extra_body. For each provider, swap in a model, a voice and its extra fields:
| model | voice | extra_body |
|---|---|---|
| maya/maya-2-native | Monika | {"language": "hi"} |
| vaakini/vaakini-tts-1 | Monika | {"language": "hi"} |
| sarvam/bulbul:v3 | shubh | {"language": "hi-IN"} |
| raya/standard | d6a002d0-230c-49b1-a137-b8a7d564b1ae | {"language": "hi"} |
| elevenlabs/eleven_flash_v2_5 | JBFqnCBsd6RMkjVDRZzb | {"voice_settings": {"stability": 0.5, "similarity_boost": 0.75}} |
| openai/gpt-4o-mini-tts | ash | None; instructions is an SDK argument |
| deepgram/aura-2 | thalia-en | None |
| xai/xai-tts | ara | {"language": "en"} |
| soniox/tts-rt-v2 | Adrian | {"language": "en"} |
| smallestai/lightning_v3.1_pro | meher | {"language": "en"} |
| cartesia/sonic-3 | f786b574-daa5-4673-aa0c-cbe3e8534c02 | {"language": "en"} |
| gemini/gemini-3.8-flash-tts | Kore | None; instructions is an SDK argument. Pass response_format="wav" or "pcm": Gemini has no mp3 |
| 60db/60db-fast-v01 | fbb75ed2-975a-40c7-9e06-38e30524a9a1 | {"wpm": 150}. Pass response_format="wav" or "pcm": 60db has no mp3 |
Body#
modelstringRequired<provider>/<model>, e.g.maya/maya-2-native,vaakini/vaakini-tts-1,sarvam/bulbul:v3,raya/standard,elevenlabs/eleven_flash_v2_5,openai/tts-1,deepgram/aura-2,xai/xai-tts,soniox/tts-rt-v2,smallestai/lightning_v3.1,cartesia/sonic-3,gemini/gemini-3.8-flash-ttsor60db/60db-fast-v01. Every model is in Models and options.inputstringRequired- The text to speak, up to 20,000 characters.
voicestringRequired- A voice of the model, as GET /v1/voices lists it: a Sarvam speaker, a Raya, ElevenLabs, Cartesia or 60db voice id, or a voice name (
Monika,ash,thalia-en,ara,Adrian,meher,Kore). Gemini: left out or null withspeakers. languagestringSarvam, Raya and Soniox: required. Maya Open-Source, Vaakini, ElevenLabs and xAI: optional. Smallest AI and Cartesia: defaulten. OpenAI, Deepgram, Gemini and 60db: not taken- The provider’s language code:
hi-INfor Sarvam,hifor Raya, Maya Open-Source and Vaakini (left out, Maya and Vaakini pick it from the script),enfor Soniox (which reads the text in that language). Left out, ElevenLabs detects the language, and xAI too (or sendauto); Smallest AI getsen(sendautofor Smallest AI to detect it), and Cartesia too. OpenAI, Gemini and 60db speak the language of the text; a Deepgram voice names its language. response_formatstringDefault"mp3"- See Formats. Gemini and 60db have no
mp3: send one of their formats. speednumberDefault1.0- Sarvam 0.5–2.0, Raya 0.5–1.5, OpenAI 0.25–4.0, Soniox 0.7–1.3, Smallest AI 0.5–2.0. Deepgram 0.7–1.5 (
aura-2only), xAI 0.7–1.5, Cartesia 0.6–1.5 and 60db 0.5–2.0: left out, the provider’s default. Maya Open-Source and Vaakini refuse it. ElevenLabs refuses it: usevoice_settings.speed. Gemini refuses it: ask for a pace ininstructions. sample_rateintegerDefault24000- Of the audio. Each provider’s rates per format are in Models and options. OpenAI, Maya Open-Source and Vaakini take only
24000; Gemini24000forpcmandwav,8000formulawandalaw; 60db8000formulaw. Left out,mulawandalawdefault to8000with ElevenLabs, Deepgram, Soniox, Gemini and 60db, and Deepgram’smp3to22050, its only rate. Sarvam also takes32000,44100and48000here, where each sentence arrives only once it is fully synthesized andbitrateis fixed at128k. temperaturenumberSarvam, Maya Open-Source and Vaakini- Sarvam: 0.01–1.0, default 0.6. Maya Open-Source: 0.1–1.5; left out, Maya's default (0.9). Vaakini: 0.1–1.5; left out, Vaakini's default.
normalizebooleanMaya Open-Source and Vaakini- Speak numbers, currency, dates and other written forms in their spoken forms. Default
true. top_kintegerMaya Open-Source and Vaakini- 1–2048. Left out, Maya's default (64), or Vaakini's.
top_pnumberMaya Open-Source and Vaakini- Above 0, up to 1. Left out, Maya's default (1.0), or Vaakini's.
repetition_penaltynumberMaya Open-Source and Vaakini- 0–5. Left out, Maya's default (0.8), or Vaakini's.
seedintegerMaya Open-Source only- A random seed. The same seed repeats a take only when the request runs alone on Maya's GPU.
dict_idstringSarvam only- A Sarvam pronunciation dictionary to apply.
pitchnumberSarvam bulbul:v4-flash only- -0.5 (deeper) to 0.5 (higher), default 0.
loudnessnumberSarvam bulbul:v4-flash only- 0.1–2.5, default 1.0.
enable_preprocessingbooleanSarvam bulbul:v4-flash only- Normalize numbers and English words in the text before synthesis. Default
false. bitratestring | integerSarvam, ElevenLabs, Soniox- Sarvam, for
mp3andaac:32k,64k,96k,128kor192k, default128k. ElevenLabs, formp3:32kat 22050 Hz,48kat 24000 Hz,32k–192kat 44100 Hz (default128k). Soniox, formp3: an integer in bits per second,32000,64000,96000,128000,192000,256000or320000(left out, Soniox’s default,128000). voice_settingsobject | nullElevenLabs only- Any of
stability,similarity_boostandstyle(0–1),speed(0.7–1.2) anduse_speaker_boost; one left out keeps the voice’s stored setting. Null: the voice’s stored settings. apply_text_normalizationstringElevenLabs onlyauto(default),onoroff.apply_language_text_normalizationbooleanElevenLabs only- Language-specific normalization (Japanese).
enable_ssml_parsingbooleanElevenLabs only- Parse SSML tags. Default
false. enable_loggingbooleanElevenLabs onlyfalsefor ElevenLabs’ zero-retention mode (enterprise accounts). Defaulttrue.pronunciation_dictionary_locatorsarrayElevenLabs only- Up to 3
{pronunciation_dictionary_id, version_id}. instructionsstringOpenAI and Gemini- How to speak: tone, accent, emotion, pace. OpenAI:
gpt-4o-mini-ttsfollows them;tts-1andtts-1-hdignore them. Gemini: style, tone, accent and pace; left out, the 2.5 and 3.1 models get LiveKit’s Gemini plugin’s default (Say the text with a proper tone, don't omit or add any words), the 3.8 models none. mip_opt_outbooleanDeepgram only- Opt out of Deepgram’s Model Improvement Program. Default
false. bit_rateintegerDeepgram, xAI, Cartesia; mp3- Deepgram:
32000or48000. xAI and Cartesia:32000,64000,96000,128000or192000. Left out, the provider’s default. optimize_streaming_latencyintegerxAI only0(best quality),1or2(a smaller first chunk for lower latency, with a quality tradeoff at chunk boundaries). Left out, xAI’s default (0).text_normalizationbooleanxAI only- Speak numbers, abbreviations and symbols in their spoken forms. Left out, xAI’s default (
false). reduce_silencebooleanSoniox only- Shorten the pauses between words. Left out, Soniox’s default (
false). volumenumberCartesia only- Loudness relative to the voice’s own, 0.5–2.0. Left out, Cartesia’s default (
1.0). emotionstringCartesia only- Guide the delivery (English), e.g.
calm,sadorangry; Cartesia lists the rest. Left out, Cartesia reads the emotion from the text. pronunciation_dict_idstringCartesia only- A Cartesia pronunciation dictionary to apply.
wpminteger60db only- The target pace in words per minute, 60–300. Left out, the voice’s own pace.
stabilityinteger60db only- 0 (expressive) to 100 (consistent). Left out, 60db’s default (
50). similarityinteger60db only- How closely the voice matches its source, 0 (loose) to 100 (exact). Left out, 60db’s default (
75). speakersobjectGemini 3.8 models only- Two speakers’ names, each with a voice:
{"Joe": "Kore", "Jane": "Puck"}. Replacesvoice, which is then left out or null. Requiresspeaker. speakerstringGemini 3.8 models only- Which of
speakersvoices this request. stream_format"audio"Default"audio"- The body is the audio itself.
sseis not supported here; OpenAI’s SSE is on the OpenAI API drop-in.
Any other field, or another provider’s, is a bad_request.
Formats#
Every format comes from the provider itself, never re-encoded. A provider and format marked No are refused with HTTP 400.
| response_format | Maya Open-Source | Vaakini | Sarvam | Raya | ElevenLabs | OpenAI | Deepgram | xAI | Soniox | Smallest AI | Cartesia | Gemini | 60db |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| pcm | 24000 Hz | 24000 Hz | Yes | Yes | Yes | 24000 Hz | Yes | Yes | Yes | Yes | Yes | 24000 Hz | Yes |
| wav | 24000 Hz | 24000 Hz | Yes | Yes | Yes | 24000 Hz | Yes | Yes | Yes | Yes | Yes | 24000 Hz | Yes |
| mp3 | 24000 Hz | 24000 Hz | Yes | m1 only | 22050, 24000, 44100 Hz | Yes | Aura, 22050 Hz | Yes | Yes | Yes | Yes | No | No |
| aac | No | No | Yes | No | No | Yes | No | No | No | No | No | No | No |
| mulaw | No | No | Yes | Yes | 8000 Hz | No | 8000, 16000 Hz | Yes | 8000 Hz | Yes | Yes | 3.8 models, 8000 Hz | 8000 Hz |
| alaw | No | No | Yes | No | 8000 Hz | No | 8000, 16000 Hz | Yes | 8000 Hz | Yes | Yes | 3.8 models, 8000 Hz | No |
pcmis raw 16-bit little-endian mono atsample_rate;wavis the same with a WAV header for streaming (its size fields are left open).mulawandalaware 8-bit G.711 atsample_rate, for telephony.
Content types: audio/pcm, audio/wav, audio/mpeg, audio/aac, audio/mulaw, audio/alaw.
Errors#
An error before any audio is a JSON body with an HTTP status. The codes are the WebSocket protocol's.
{ "error": { "code": "provider_rejected", "message": "…", "retryable": false, "provider_status": 403 }}bad_requestHTTP 400, not retryable- The request failed validation or a message arrived out of order. The message says which field or rule.
unauthorizedHTTP 401, not retryable- The API key is missing, wrong or deleted, or its org is disabled.
insufficient_creditsHTTP 402, not retryable- Your org is out of credit, so the router refuses new connections and requests until you buy more. Connections already open carry on.
provider_key_missingHTTP 400, not retryable- Your org has no key stored for the provider. Add one under Provider keys. Maya Open-Source needs none.
provider_rejectedHTTP 400, not retryable- The provider refused the request, e.g. a wrong stored provider key or an unknown voice. The provider’s message is passed through.
provider_rate_limitedHTTP 429, retryable- Your own quota at the provider is exhausted, or Maya Open-Source is at capacity (the message says so); try again in a moment.
provider_unavailableHTTP 502, retryable- The provider returned a server error, or the connection to it failed or closed unexpectedly.
provider_timeoutHTTP 504, retryable- The provider took too long to send audio.
internalHTTP 500, retryable- The router failed.
After audio has started#
The status line goes out with the first audio, so a sentence that fails later can’t change it to an error. The router aborts the response instead, so it ends early: the body (chunked, with no Content-Length) ends without its final chunk, and your HTTP client raises an error rather than returning a short file:
| Client | Raises |
|---|---|
OpenAI SDK, with_streaming_response | httpx.RemoteProtocolError (incomplete chunked read) |
OpenAI SDK, create() | openai.APIConnectionError, after the SDK’s own retries |
| httpx | httpx.RemoteProtocolError |
| requests | requests.exceptions.ChunkedEncodingError |
| aiohttp | aiohttp.ClientPayloadError |
| Node fetch | TypeError: terminated while reading the body |
| curl | Exit code 18, transfer closed with outstanding read data remaining |
Treat it as a failed request, and don’t keep the audio you received as a finished file. Retrying the same request is cheap: the sentences that finished before the failure are already in your cache, so only the rest go to the provider again. For an explicit error with its code and retryable, per segment, use the WebSocket protocol.