Skip to main content
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

Choose a group in your API key settings, or use smart routing.

Speech API

This request saves the generated audio to speech.mp3:
A successful response contains audio bytes in the requested format.

Native Gemini API

Put the model ID in the URL and set responseModalities to ["AUDIO"].
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 for prices. Speech requests appear in Common Logs. See Billing and tiers for reserved funds and Account and usage 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.

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.
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.

Response formats and limits

The three reviewed speech variants return synchronously. No video task polling is needed. Compatible Speech returns binary audio directly:
Gemini returns inline base64 with its media type:
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; do not infer a duration charge from audio length.