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

# Audio and speech

> Generate speech through compatible, Gemini and MiniMax APIs. Read binary, base64 and hex responses, with reviewed voice limits, errors and billing notes.

Turn text into speech with OpenAI and Gemini models. Use the Speech API for `gpt-4o-mini-tts` and the native Gemini API for Gemini speech models.

## Speech models

| Model ID | API | Routing groups |
| - | - | - |
| `gpt-4o-mini-tts` | Speech | `Azure-Gpt-5`, `Azure-Gpt-4`, `Azure-Gpt-2`, `Azure-Gpt-1`, `Azure-Gpt-3` |
| `gemini-2.5-flash-preview-tts` | Gemini | `Aistudio-Gemini-4`, `Aistudio-Gemini-3` |
| `gemini-2.5-pro-preview-tts` | Gemini | `Aistudio-Gemini-4`, `Aistudio-Gemini-3` |
| `gemini-3.1-flash-tts-preview` | Gemini | `Vertex-Gemini-3`, `Aistudio-Gemini-3`, `Aistudio-Gemini-2`, `Vertex-Gemini-2`, `Aistudio-Gemini-4` |
| `gemini-3.8-flash-tts` | Gemini | `Aistudio-Gemini-2`, `Vertex-Gemini-2`, `Vertex-Gemini-3`, `Aistudio-Gemini-4`, `Aistudio-Gemini-3` |

Choose a group in your [API key settings](https://docs.floodgate.dev/routing-groups.md), or use smart routing.

## Speech API

This request saves the generated audio to `speech.mp3`:

```bash theme={null}
curl "https://api.floodgate.dev/v1/audio/speech" \
  -H "Authorization: Bearer $FLOODGATE_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-4o-mini-tts",
    "input": "Welcome to Floodgate.",
    "voice": "alloy",
    "response_format": "mp3"
  }' \
  --output speech.mp3
```

A successful response contains audio bytes in the requested format.

| Field | Accepted values |
| - | - |
| `input` | Non-empty text, up to 4,096 characters |
| `voice` | `alloy`, `ash`, `ballad`, `coral`, `echo`, `fable`, `nova`, `onyx`, `sage`, `shimmer`, `verse`, `marin`, or `cedar` |
| `instructions` | Optional voice instructions, up to 4,096 characters |
| `response_format` | `mp3`, `opus`, `aac`, `flac`, `wav`, or `pcm` |
| `speed` | A number from 0.25 to 4 |
| `stream_format` | `audio` for the reviewed binary response |

## Native Gemini API

Put the model ID in the URL and set `responseModalities` to `["AUDIO"]`.

```bash theme={null}
curl "https://api.floodgate.dev/v1beta/models/gemini-3.1-flash-tts-preview:generateContent" \
  -H "Authorization: Bearer $FLOODGATE_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "contents": [{"parts": [{"text": "Say warmly: Welcome to Floodgate."}]}],
    "generationConfig": {
      "responseModalities": ["AUDIO"],
      "candidateCount": 1,
      "maxOutputTokens": 1024
    }
  }'
```

Send one content item with one text part and set `candidateCount` to `1`. To select a voice, set `speechConfig.voiceConfig.prebuiltVoiceConfig.voiceName` inside `generationConfig` to a supported Gemini voice.

The response contains base64 audio and a MIME type in its audio parts. Decode the data using the reported encoding.

## Pricing and usage

Speech pricing depends on the model and routing group. Gemini speech uses confirmed audio and text token usage. Check [Model Square](https://floodgate.dev/models) for prices.

Speech requests appear in Common Logs. See [Billing and tiers](https://docs.floodgate.dev/billing.md) for reserved funds and [Account and usage](https://docs.floodgate.dev/api-reference/account-usage.md) for spending records.

To generate speech from a coding tool, add a script, function, or MCP tool that calls the speech endpoint and saves the audio. See [Coding tools](https://docs.floodgate.dev/agents/overview.md).

## MiniMax speech

The reviewed native speech operation is `POST /minimax/v1/t2a_v2` for `speech-02-hd`, `speech-02-turbo`, `speech-2.6-hd`, `speech-2.6-turbo`, `speech-2.8-hd` and `speech-2.8-turbo` in `Hailuo-1`. Check current availability in [Model Square](https://floodgate.dev/models).

```bash theme={null}
curl --fail-with-body https://api.floodgate.dev/minimax/v1/t2a_v2 \
  -H "Authorization: Bearer $FLOODGATE_API_KEY" -H 'Content-Type: application/json' \
  -d '{"model":"speech-2.8-hd","text":"Hello!","stream":false,"voice_setting":{"voice_id":"English_Graceful_Lady"},"audio_setting":{"format":"mp3"},"output_format":"hex"}'
```

| Field | Required | Limits |
| - | - | - |
| `model`, `text` | Yes | Accepted model ID; 1 to 10,000 Unicode characters, not whitespace-only |
| `voice_setting.voice_id` | Yes | Nonempty provider voice ID; no enforced voice-name list |
| `voice_setting.speed` | No | 0.5 to 2 |
| `voice_setting.vol` | No | 0.01 to 10 |
| `voice_setting.pitch` | No | -12 to 12 |
| `audio_setting.format` | No | `mp3`, `pcm`, `flac`, `wav` |
| `audio_setting.sample_rate` | No | Integer, 8,000 to 44,100 Hz |
| `audio_setting.bitrate` | No | Integer, 32,000 to 256,000 |
| `audio_setting.channel` | No | Integer, 1 or 2 |
| `output_format` | No | `hex` or `url` |
| `stream` | No | Use `false` for this complete-response example |

```json theme={null}
{"data":{"audio":"494433","status":2},"extra_info":{"usage_characters":6},"base_resp":{"status_code":0,"status_msg":"success"}}
```

Check `base_resp.status_code: 0` and terminal `data.status: 2` before using audio or billed characters. Errors can arrive inside HTTP 200. For `hex`, decode `data.audio` to bytes; with `url`, it is a download URL. The sample audio is shortened.

```python theme={null}
from pathlib import Path

if data["base_resp"]["status_code"] != 0 or data["data"]["status"] != 2:
    raise RuntimeError(data)
Path("speech.mp3").write_bytes(bytes.fromhex(data["data"]["audio"]))
```

## Response formats and limits

The three reviewed speech variants return synchronously. No video task polling is needed.

Compatible Speech returns binary audio directly:

```http theme={null}
HTTP/1.1 200 OK
Content-Type: audio/mpeg

<binary MP3 audio bytes>
```

Gemini returns inline base64 with its media type:

```json theme={null}
{"candidates":[{"content":{"role":"model","parts":[{"inlineData":{"mimeType":"audio/L16;codec=pcm;rate=24000","data":"AAABAA=="}}]},"finishReason":"STOP"}],"usageMetadata":{"promptTokenCount":2,"candidatesTokenCount":4,"totalTokenCount":6}}
```

Decode `inlineData.data` and inspect `inlineData.mimeType`. Raw PCM needs the reported sample rate and channel configuration for playback or a WAV header. Do not guess the format from a filename. This inline sample is shortened.

Compatible Speech counts Unicode code points and rejects whitespace-only input. Its reviewed text/instructions ceilings are 4,096 characters each. Gemini permits one content, one text part and one candidate with `responseModalities: ["AUDIO"]`. Its voice-name list, input-character ceiling and output encodings are undocumented; its published output-token ceiling is a gateway safeguard, not a model capacity claim. Defaults remain undocumented.

Transcription, translation, realtime, audio chat, music, voice creation, uploads and Gemini speech streaming need separate reviewed contracts. This page covers non-streaming speech only.

## Errors and billing notes

Check required fields and limits on `400`, the API key on `401`, group access and funds on `403`, and rate limits on `429`. Inspect Gemini finish/block fields and MiniMax's native status fields even after HTTP success.

Compatible Speech uses a completed-request price. Gemini speech uses confirmed token usage. MiniMax uses `extra_info.usage_characters` from a successful terminal response. See the selected group's prices in [Model Square](https://floodgate.dev/models); do not infer a duration charge from audio length.


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