> ## Documentation Index
> Fetch the complete documentation index at: https://docs.gradium.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Text-to-Speech on Baseten

> Stream Gradium TTS from a dedicated deployment hosted on Baseten

Your dedicated Gradium Text-to-Speech deployment runs on Baseten and
speaks the same streaming WebSocket protocol as the hosted Gradium API.
Only the connection details change: the URL and the authentication
header.

## Differences from the hosted API

| | Hosted Gradium API | Baseten deployment |
| - | - | - |
| WebSocket URL | `wss://api.gradium.ai/api/speech/tts` | The URL Baseten gives you, e.g. `wss-host.example.com/websocket` — the TTS WebSocket is served at that URL directly |
| Authentication | `x-api-key: <Gradium API key>` | `Authorization: Api-Key <Baseten API key>` |
| Voice catalog | Full voice library + your custom voices | The voices baked into the deployment image (see [Available voices](#available-voices)) |
| Pronunciation dictionaries (`pronunciation_id`) | Available | Not available — use inline [`rewrites`](#setup-parameters) instead |

## Prerequisites

* The WebSocket URL of your deployment (provided by Baseten / Gradium),
  of the form `wss-host.example.com/websocket`.
* A Baseten API key with access to the deployment.
* Python 3.10+ with the Gradium SDK, version **0.6.1 or later**
  (`pip install "gradium>=0.6.1"`). Earlier versions cannot override the
  TTS route and will not reach a self-hosted deployment.

## Quickstart

The SDK repository ships a ready-made client for self-hosted
deployments:
[`examples/self_hosted/example_tts.py`](https://github.com/gradium-ai/gradium-py/blob/main/examples/self_hosted/example_tts.py).
It connects to the deployment, synthesizes the given text, and writes
the audio to a file:

```bash theme={null}
uv run examples/self_hosted/example_tts.py \
  --base-url wss-host.example.com/websocket \
  --api-key "<your Baseten API key>" \
  --text "Hello from Baseten!" \
  --voice NbpkqMVS3CJeq2j8 \
  --output-format wav \
  --output out.wav
```

> [!NOTE]
>
> `--api-key` takes your **Baseten** API key — the example client sends
> it in Baseten's `Authorization: Api-Key ...` header, not in the hosted
> API's `x-api-key` header.

### Minimal client

The example boils down to two adjustments to the standard
`GradiumClient`, both worth copying into your own code:

1. **`tts_route=""`** — on the hosted API the client appends
   `speech/tts` to the base URL; on Baseten the TTS WebSocket is served
   at the deployment URL directly.
2. **Auth header override** — Baseten authenticates with
   `Authorization: Api-Key <key>`.

```python theme={null}
import asyncio

from gradium import GradiumClient
from gradium.client import SOURCE


class SelfHostedTTSClient(GradiumClient):
    """GradiumClient for a self-hosted / Baseten deployment."""

    @property
    def headers(self) -> dict:
        return {
            "Authorization": f"Api-Key {self._api_key}",
            "x-api-source": SOURCE,
        }


async def main():
    client = SelfHostedTTSClient(
        base_url="wss-host.example.com/websocket",
        api_key="<your Baseten API key>",
        tts_route="",  # the TTS WebSocket is served at the base URL directly
    )
    setup = {"voice_id": "NbpkqMVS3CJeq2j8", "output_format": "wav"}

    stream = await client.tts_stream(setup, "Hello from Baseten!")
    audio = b"".join([chunk async for chunk in stream.iter_bytes()])

    with open("out.wav", "wb") as f:
        f.write(audio)


asyncio.run(main())
```

All three SDK shapes work against the deployment exactly as described
in the [Text-to-Speech guide](https://docs.gradium.ai/guides/text-to-speech.md): `tts_realtime`
for concurrent send/receive, `tts_stream` for an async iterator of
audio chunks, and `tts` for buffered one-shot synthesis.

## Setup parameters

* **`voice_id`**: The id of the voice to use, from
  [Available voices](#available-voices) below. Omit it to use the
  deployment's default voice.
* **`output_format`**: `"wav"` or `"pcm"`. PCM output is 48kHz,
  16-bit signed integer, mono.
* **`json_config`**: Advanced voice settings such as temperature and
  speed. See [Voice Settings](https://docs.gradium.ai/guides/voice-settings.md).
* **`rewrites`**: Inline text rewrite rules, as a list of
  `[original, rewrite, case_sensitive]` entries. See
  [Text Rewriting](https://docs.gradium.ai/guides/text-rewriting.md).

## Direct WebSocket

From a non-Python runtime, talk to the WebSocket directly. The message
flow is the same as the
[TTS WebSocket reference](https://docs.gradium.ai/api-reference/endpoint/tts-websocket.md):
send `setup`, wait for `ready`, send `text` and `end_of_stream`,
receive `audio` / `text` messages until `end_of_stream`.

```bash theme={null}
wscat -c "wss://<your-deployment-host>/websocket" \
  -H "Authorization: Api-Key $BASETEN_API_KEY"
# After connection, type:
# {"type":"setup","voice_id":"NbpkqMVS3CJeq2j8","output_format":"wav"}
# {"type":"text","text":"Hello, world!"}
# {"type":"end_of_stream"}
```

The only difference from the hosted reference: `pronunciation_id` is
not available — use inline [`rewrites`](#setup-parameters) instead.

## Troubleshooting

| Symptom | Cause | Fix |
| - | - | - |
| Error: `voice_id '<id>' not found` | The id isn't baked into the deployment image | Check the id against [Available voices](#available-voices) |
| Connection rejected (401/403) | Wrong auth header | Send `Authorization: Api-Key <Baseten API key>` — not `x-api-key` |
| WebSocket closes right after connecting | The deployment replica is still warming up (\~3 min after a cold start or scale-up) | Retry with backoff |

## Available voices

The deployment image ships with **346 voices** plus a built-in default
voice (used when `voice_id` is omitted). All 66
[flagship voices](https://docs.gradium.ai/guides/voices/flagship-voices.md) are included — the
tables below list them per language; the full id list follows. Pass
the id as the `voice_id` setup field — click an id to copy it. You can
also listen to and test the voices in the official
[Gradium Studio](https://studio.gradium.ai/).

> [tab] English (18)
>
> <table>
>   <thead>
>     <tr>
>       <th />
>
>       <th />
>
>       <th />
>
>       <th />
>     </tr>
>   </thead>
>
>   <tbody />
> </table>

> [tab] French (13)
>
> <table>
>   <thead>
>     <tr>
>       <th />
>
>       <th />
>
>       <th />
>
>       <th />
>     </tr>
>   </thead>
>
>   <tbody />
> </table>

> [tab] German (13)
>
> <table>
>   <thead>
>     <tr>
>       <th />
>
>       <th />
>
>       <th />
>
>       <th />
>     </tr>
>   </thead>
>
>   <tbody />
> </table>

> [tab] Spanish (14)
>
> <table>
>   <thead>
>     <tr>
>       <th />
>
>       <th />
>
>       <th />
>
>       <th />
>     </tr>
>   </thead>
>
>   <tbody />
> </table>

> [tab] Portuguese (8)
>
> <table>
>   <thead>
>     <tr>
>       <th />
>
>       <th />
>
>       <th />
>
>       <th />
>     </tr>
>   </thead>
>
>   <tbody />
> </table>

> [accordion] Full voice id list (346)
>
> Every id below is baked into the deployment image and usable as the
> `voice_id` setup field, including the flagship voices listed above.
>
> ```text theme={null}
> wGhY_zZCoQ5gB0ce
> Y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XjVvZ6oDDGQAQFj
> WxHB2b5HxA0Kuq5u
> dK5Glio51HTxdMu0
> Abqwk2RWxlBEyv0j
> KEMqb7dQlTCAEUx6
> 9LhjfdN9LOrygqDi
> bauuigqCZbJFfk5q
> ZsVFAOnjnEPxJVDI
> AEJ61XaIaRill4cJ
> 9QHzSiOYUD-RzEzM
> sz-H9BxaRaqxQ2S0
> FRTqjB2TL-Ix9GXW
> 3mM3xaoFjNMQa22C
> AySdCEnP2nqRo1WM
> -_aUUFZaJ0CT1gks
> s4CzgVHP5cEkB9LD
> hAdJ9w9xBQkFgrRl
> J4XbCGPYNMigXcfZ
> NoJdNY6JTz-VJLwz
> xB86uC_i8sO2U41-
> L7890s1B44FqSiGC
> vbg20SqFS_gBntTQ
> VXA4-0_ZN4o8q3vK
> lHL_BeE8kcYk_PFm
> FvHwyEGJDAnhCOmy
> IvU7qOuioP04a4eX
> d1HpinVF79zaGnJY
> cMvT_WqtiQCCf9c4
> yk80SYvdMuQFF1MD
> mweCx1v9-T6gDXH8
> 3YlG68yLpoTW8HEj
> vzanWTXLIajkUaaT
> IlWrXUM6C11vXm1S
> 8_M2uwvmyM-BadY9
> aq7ltaIQ6ZJUY0jR
> RhI-l8fGE2DtXgXV
> HtgP9v8SoWbq_jxi
> 3jUdJyOi9pgbxBTK
> 2H4HY2CBNyJHBCrP
> IIZIkBSZAmb9nFZb
> PS7enm5lVZiIvEKV
> b-1LP0pKWL1tNgml
> c8BzreHTk1GG2R4z
> mmLFHtCjt_6jw0vT
> sX0PcxM_Ie2ctBGH
> sBLwTd5womVX8JOw
> TXbEUrHXNFlYBBKb
> Xtp0vUDvtAfi1xkH
> BPHlOW9jPs79KtW4
> 4NLtOv1m0azv9rGL
> VDwnGxAo68C8U8vC
> s58clrg2fe0MO7Y-
> yHToO6ssaQHz5kIP
> n7vovxcDTVG4gClo
> tWll9uiMafMXfOGw
> ```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.