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.

View as Markdown

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")

Fields the OpenAI SDK doesn’t have go in extra_body. For each provider, swap in a model, a voice and its extra fields:

modelvoiceextra_body
maya/maya-2-nativeMonika{"language": "hi"}
vaakini/vaakini-tts-1Monika{"language": "hi"}
sarvam/bulbul:v3shubh{"language": "hi-IN"}
raya/standardd6a002d0-230c-49b1-a137-b8a7d564b1ae{"language": "hi"}
elevenlabs/eleven_flash_v2_5JBFqnCBsd6RMkjVDRZzb{"voice_settings": {"stability": 0.5, "similarity_boost": 0.75}}
openai/gpt-4o-mini-ttsashNone; instructions is an SDK argument
deepgram/aura-2thalia-enNone
xai/xai-ttsara{"language": "en"}
soniox/tts-rt-v2Adrian{"language": "en"}
smallestai/lightning_v3.1_promeher{"language": "en"}
cartesia/sonic-3f786b574-daa5-4673-aa0c-cbe3e8534c02{"language": "en"}
gemini/gemini-3.8-flash-ttsKoreNone; instructions is an SDK argument. Pass response_format="wav" or "pcm": Gemini has no mp3
60db/60db-fast-v01fbb75ed2-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-tts or 60db/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 with speakers.
languagestringSarvam, Raya and Soniox: required. Maya Open-Source, Vaakini, ElevenLabs and xAI: optional. Smallest AI and Cartesia: default en. OpenAI, Deepgram, Gemini and 60db: not taken
The provider’s language code: hi-IN for Sarvam, hi for Raya, Maya Open-Source and Vaakini (left out, Maya and Vaakini pick it from the script), en for Soniox (which reads the text in that language). Left out, ElevenLabs detects the language, and xAI too (or send auto); Smallest AI gets en (send auto for 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.
speednumberDefault 1.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-2 only), 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: use voice_settings.speed. Gemini refuses it: ask for a pace in instructions.
sample_rateintegerDefault 24000
Of the audio. Each provider’s rates per format are in Models and options. OpenAI, Maya Open-Source and Vaakini take only 24000; Gemini 24000 for pcm and wav, 8000 for mulaw and alaw; 60db 8000 for mulaw. Left out, mulaw and alaw default to 8000 with ElevenLabs, Deepgram, Soniox, Gemini and 60db, and Deepgram’s mp3 to 22050, its only rate. Sarvam also takes 32000, 44100 and 48000 here, where each sentence arrives only once it is fully synthesized and bitrate is fixed at 128k.
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 mp3 and aac: 32k, 64k, 96k, 128k or 192k, default 128k. ElevenLabs, for mp3: 32k at 22050 Hz, 48k at 24000 Hz, 32k–192k at 44100 Hz (default 128k). Soniox, for mp3: an integer in bits per second, 32000, 64000, 96000, 128000, 192000, 256000 or 320000 (left out, Soniox’s default, 128000).
voice_settingsobject | nullElevenLabs only
Any of stability, similarity_boost and style (0–1), speed (0.7–1.2) and use_speaker_boost; one left out keeps the voice’s stored setting. Null: the voice’s stored settings.
apply_text_normalizationstringElevenLabs only
auto (default), on or off.
apply_language_text_normalizationbooleanElevenLabs only
Language-specific normalization (Japanese).
enable_ssml_parsingbooleanElevenLabs only
Parse SSML tags. Default false.
enable_loggingbooleanElevenLabs only
false for ElevenLabs’ zero-retention mode (enterprise accounts). Default true.
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-tts follows them; tts-1 and tts-1-hd ignore 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: 32000 or 48000. xAI and Cartesia: 32000, 64000, 96000, 128000 or 192000. Left out, the provider’s default.
optimize_streaming_latencyintegerxAI only
0 (best quality), 1 or 2 (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, sad or angry; 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"}. Replaces voice, which is then left out or null. Requires speaker.
speakerstringGemini 3.8 models only
Which of speakers voices this request.
stream_format"audio"Default "audio"
The body is the audio itself. sse is 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_formatMaya Open-SourceVaakiniSarvamRayaElevenLabsOpenAIDeepgramxAISonioxSmallest AICartesiaGemini60db
pcm24000 Hz24000 HzYesYesYes24000 HzYesYesYesYesYes24000 HzYes
wav24000 Hz24000 HzYesYesYes24000 HzYesYesYesYesYes24000 HzYes
mp324000 Hz24000 HzYesm1 only22050, 24000, 44100 HzYesAura, 22050 HzYesYesYesYesNoNo
aacNoNoYesNoNoYesNoNoNoNoNoNoNo
mulawNoNoYesYes8000 HzNo8000, 16000 HzYes8000 HzYesYes3.8 models, 8000 Hz8000 Hz
alawNoNoYesNo8000 HzNo8000, 16000 HzYes8000 HzYesYes3.8 models, 8000 HzNo
  • pcm is raw 16-bit little-endian mono at sample_rate; wav is the same with a WAV header for streaming (its size fields are left open).
  • mulaw and alaw are 8-bit G.711 at sample_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.

JSON
{  "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:

ClientRaises
OpenAI SDK, with_streaming_responsehttpx.RemoteProtocolError (incomplete chunked read)
OpenAI SDK, create()openai.APIConnectionError, after the SDK’s own retries
httpxhttpx.RemoteProtocolError
requestsrequests.exceptions.ChunkedEncodingError
aiohttpaiohttp.ClientPayloadError
Node fetchTypeError: terminated while reading the body
curlExit 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.