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

# Text to speech (TTS)

> POST /v1/audio/speech — synthesize text into speech

Synthesize text into natural-sounding speech.

## Request

```bash theme={null}
curl https://openp.ai/v1/audio/speech \
  -H "Authorization: Bearer $OPENPAI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "tts-1",
    "input": "Hello from OpenPAI",
    "voice": "alloy",
    "response_format": "mp3"
  }' --output speech.mp3
```

### Parameters

| Field             | Type   | Required | Description                                                                               |
| ----------------- | ------ | :------: | ----------------------------------------------------------------------------------------- |
| `model`           | string |     ✅    | `tts-1` / `tts-1-hd` / `gpt-4o-mini-tts`                                                  |
| `input`           | string |     ✅    | The text to synthesize (up to 4096 characters)                                            |
| `voice`           | string |     ✅    | Voice: `alloy` / `echo` / `fable` / `onyx` / `nova` / `shimmer` / `coral` / `verse`, etc. |
| `response_format` | string |          | `mp3` (default) / `opus` / `aac` / `flac` / `wav` / `pcm`                                 |
| `speed`           | number |          | 0.25 - 4.0 (default 1.0)                                                                  |
| `instructions`    | string |          | `gpt-4o-mini-tts` only; describe tone / style                                             |

## Response

Returns a **binary audio stream** directly, with `Content-Type` matching the chosen `response_format`:

| response\_format | Content-Type |
| ---------------- | ------------ |
| `mp3`            | `audio/mpeg` |
| `opus`           | `audio/ogg`  |
| `aac`            | `audio/aac`  |
| `flac`           | `audio/flac` |
| `wav`            | `audio/wav`  |
| `pcm`            | `audio/pcm`  |

## Python example

```python theme={null}
from openai import OpenAI
client = OpenAI(api_key="sk-...", base_url="https://openp.ai/v1")

with client.audio.speech.with_streaming_response.create(
    model="tts-1-hd",
    voice="nova",
    input="OpenPAI makes integrating LLMs simpler.",
) as resp:
    resp.stream_to_file("output.mp3")
```

## gpt-4o-mini-tts advanced

The next-gen TTS supports controlling tone via `instructions`:

```json theme={null}
{
  "model": "gpt-4o-mini-tts",
  "voice": "coral",
  "input": "Today's meeting results were excellent.",
  "instructions": "Read in an excited, upbeat tone, slightly faster."
}
```

## Streaming playback

Synthesis may take ≥ 1 second; in a browser or client you can receive it as a stream:

```python theme={null}
with client.audio.speech.with_streaming_response.create(
    model="tts-1",
    voice="alloy",
    input="...",
    response_format="opus",
) as resp:
    for chunk in resp.iter_bytes():
        # play as you receive
        play(chunk)
```

## Billing

Charged by **input character count**, regardless of the chosen model and format.
