# /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](https://docs.ttscacherouter.dev/index.md#regions) 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.

**OpenAI SDK**

```python
import os

from openai import OpenAI

client = 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**

```shell
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.wav
```

Fields 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

- `model` (`string`, Required): `<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](https://docs.ttscacherouter.dev/reference/models.md).
- `input` (`string`, Required): The text to speak, up to 20,000 characters.
- `voice` (`string`, Required): A voice of the model, as [GET /v1/voices](https://docs.ttscacherouter.dev/reference/voices.md) 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`.
- `language` (`string`, Sarvam, 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_format` (`string`, Default `"mp3"`): See [Formats](https://docs.ttscacherouter.dev/clients/speech.md#formats). Gemini and 60db have no `mp3`: send one of their formats.
- `speed` (`number`, Default `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_rate` (`integer`, Default `24000`): Of the audio. Each provider’s rates per format are in [Models and options](https://docs.ttscacherouter.dev/reference/models.md). 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`.
- `temperature` (`number`, Sarvam, 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.
- `normalize` (`boolean`, Maya Open-Source and Vaakini): Speak numbers, currency, dates and other written forms in their spoken forms. Default `true`.
- `top_k` (`integer`, Maya Open-Source and Vaakini): 1–2048. Left out, Maya's default (64), or Vaakini's.
- `top_p` (`number`, Maya Open-Source and Vaakini): Above 0, up to 1. Left out, Maya's default (1.0), or Vaakini's.
- `repetition_penalty` (`number`, Maya Open-Source and Vaakini): 0–5. Left out, Maya's default (0.8), or Vaakini's.
- `seed` (`integer`, Maya Open-Source only): A random seed. The same seed repeats a take only when the request runs alone on Maya's GPU.
- `dict_id` (`string`, Sarvam only): A Sarvam pronunciation dictionary to apply.
- `pitch` (`number`, Sarvam bulbul:v4-flash only): -0.5 (deeper) to 0.5 (higher), default 0.
- `loudness` (`number`, Sarvam bulbul:v4-flash only): 0.1–2.5, default 1.0.
- `enable_preprocessing` (`boolean`, Sarvam bulbul:v4-flash only): Normalize numbers and English words in the text before synthesis. Default `false`.
- `bitrate` (`string | integer`, Sarvam, 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_settings` (`object | null`, ElevenLabs 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_normalization` (`string`, ElevenLabs only): `auto` (default), `on` or `off`.
- `apply_language_text_normalization` (`boolean`, ElevenLabs only): Language-specific normalization (Japanese).
- `enable_ssml_parsing` (`boolean`, ElevenLabs only): Parse SSML tags. Default `false`.
- `enable_logging` (`boolean`, ElevenLabs only): `false` for ElevenLabs’ zero-retention mode (enterprise accounts). Default `true`.
- `pronunciation_dictionary_locators` (`array`, ElevenLabs only): Up to 3 `{pronunciation_dictionary_id, version_id}`.
- `instructions` (`string`, OpenAI 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_out` (`boolean`, Deepgram only): Opt out of Deepgram’s Model Improvement Program. Default `false`.
- `bit_rate` (`integer`, Deepgram, xAI, Cartesia; mp3): Deepgram: `32000` or `48000`. xAI and Cartesia: `32000`, `64000`, `96000`, `128000` or `192000`. Left out, the provider’s default.
- `optimize_streaming_latency` (`integer`, xAI 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_normalization` (`boolean`, xAI only): Speak numbers, abbreviations and symbols in their spoken forms. Left out, xAI’s default (`false`).
- `reduce_silence` (`boolean`, Soniox only): Shorten the pauses between words. Left out, Soniox’s default (`false`).
- `volume` (`number`, Cartesia only): Loudness relative to the voice’s own, 0.5–2.0. Left out, Cartesia’s default (`1.0`).
- `emotion` (`string`, Cartesia 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_id` (`string`, Cartesia only): A Cartesia pronunciation dictionary to apply.
- `wpm` (`integer`, 60db only): The target pace in words per minute, 60–300. Left out, the voice’s own pace.
- `stability` (`integer`, 60db only): 0 (expressive) to 100 (consistent). Left out, 60db’s default (`50`).
- `similarity` (`integer`, 60db only): How closely the voice matches its source, 0 (loose) to 100 (exact). Left out, 60db’s default (`75`).
- `speakers` (`object`, Gemini 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`.
- `speaker` (`string`, Gemini 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](https://docs.ttscacherouter.dev/providers/openai.md#http).

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 |

- `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_request` (HTTP 400, not retryable): The request failed validation or a message arrived out of order. The message says which field or rule.
- `unauthorized` (HTTP 401, not retryable): The API key is missing, wrong or deleted, or its org is disabled.
- `insufficient_credits` (HTTP 402, not retryable): Your org is out of credit, so the router refuses new connections and requests until you [buy more](https://app.ttscacherouter.dev/app/billing). Connections already open carry on.
- `provider_key_missing` (HTTP 400, not retryable): Your org has no key stored for the provider. Add one under [Provider keys](https://app.ttscacherouter.dev/app/provider-keys). Maya Open-Source needs none.
- `provider_rejected` (HTTP 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_limited` (HTTP 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_unavailable` (HTTP 502, retryable): The provider returned a server error, or the connection to it failed or closed unexpectedly.
- `provider_timeout` (HTTP 504, retryable): The provider took too long to send audio.
- `internal` (HTTP 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](https://docs.ttscacherouter.dev/clients/stream.md#errors).
