Audio · OpenAI
GPT-4o mini TTS API Docs: Parameters and Examples
GPT-4o mini TTS is OpenAI’s text-to-speech model, served on TokenRa behind the standard /v1/audio/speech endpoint. Send JSON with the text and a voice and the response body is the audio file itself. Steer the tone with instructions, or set stream_format to sse to receive audio chunks as they are generated. Text input costs $0.9 per million tokens and generated audio $31.5 per million tokens, roughly $0.03 to $0.04 per minute of speech.
- Model ID
gpt-4o-mini-tts- Provider
- OpenAI
- Mode
- Synchronous or SSE stream
- Input price
- $0.9 / 1M tokens
- Output price
- $31.5 / 1M audio tokens
- Max input
- 4 096 characters
Endpoint
API endpoint
application/json. Returns the audio file in the response body, or an SSE stream when stream_format is sse.Parameters
Request parameters
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
model | string | Yes | — | Must be gpt-4o-mini-tts. |
input | string | Yes | — | The text to speak, up to 4 096 characters. Longer text returns 400; split it and join the audio. |
voice | string | Yes | — | One of the voices listed below. A missing or unknown voice returns 400. |
instructions | string | No | — | Free-text direction for tone, pace, accent or emotion, e.g. “Speak in a calm, warm tone.” |
response_format | string | No | mp3 | One of mp3, opus, aac, wav, pcm. |
speed | number | No | 1 | Speed from 0.25 to 4.0. Values outside the range return 400. |
stream_format | string | No | audio | Set to sse to stream Server-Sent Events instead of one audio body. See Streaming below. |
Output
Audio formats and voices
| Value | Content-Type | Use when |
|---|---|---|
mp3 | audio/mpeg | Default. Plays everywhere. |
opus | audio/opus | Low-latency streaming and web audio. |
aac | audio/aac | Mobile playback and video editors. |
wav | audio/wav | Uncompressed audio for editing. |
pcm | audio/pcm | Raw 24 kHz 16-bit mono samples with no header. |
Voices
Thirteen voices are available: alloy, ash, ballad, coral, echo, fable, nova, onyx, sage, shimmer, verse, marin, cedar. An unknown name returns 400.
Examples
Code examples
cURL
curl https://tokenra.io/v1/audio/speech \
-H "Authorization: Bearer $TOKENRA_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-4o-mini-tts",
"input": "Today is a wonderful day to build something people love!",
"voice": "coral",
"instructions": "Speak in a cheerful and positive tone.",
"response_format": "mp3"
}' \
--output speech.mp3Python (openai SDK)
from openai import OpenAI
client = OpenAI(
api_key="YOUR_TOKENRA_API_KEY",
base_url="https://tokenra.io/v1",
)
with client.audio.speech.with_streaming_response.create(
model="gpt-4o-mini-tts",
voice="coral",
input="Today is a wonderful day to build something people love!",
instructions="Speak in a cheerful and positive tone.",
response_format="mp3",
) as response:
response.stream_to_file("speech.mp3")JavaScript (fetch)
import { writeFile } from "node:fs/promises";
const res = await fetch("https://tokenra.io/v1/audio/speech", {
method: "POST",
headers: {
Authorization: "Bearer " + process.env.TOKENRA_API_KEY,
"Content-Type": "application/json",
},
body: JSON.stringify({
model: "gpt-4o-mini-tts",
voice: "alloy",
input: "Hello from TokenRa.",
response_format: "mp3",
}),
});
if (!res.ok) throw new Error(res.status + " " + (await res.text()));
await writeFile("speech.mp3", Buffer.from(await res.arrayBuffer()));Streaming (SSE)
curl -N https://tokenra.io/v1/audio/speech \
-H "Authorization: Bearer $TOKENRA_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-4o-mini-tts",
"input": "Streaming speech from TokenRa.",
"voice": "alloy",
"stream_format": "sse"
}'Each speech.audio.delta event carries a base64 audio chunk in the audio field. The stream ends with a speech.audio.done event whose usage object holds input_tokens, output_tokens and total_tokens.
Billing
Billing
Every request is metered on two items:
- Input text: $0.9 per million tokens.
- Generated audio: $31.5 per million audio tokens. A normal call counts 1 000 tokens per minute of audio, rounded up to the next second. With
stream_formatset tosse, the token count the upstream reports in the final event is billed instead.
Errors
Error codes
| HTTP | Typical message | Cause |
|---|---|---|
| 400 | input is required, voice is required | A required field is missing. |
| 400 | invalid voice: ... | Unknown voice name. |
| 400 | speed must be between 0.25 and 4.00 | The speed value is out of range. |
| 400 | input exceeds maximum length of 4096 characters | Input is longer than 4 096 characters. |
| 400 | invalid response_format: ... | Unsupported output format. |
| 401 | Invalid token | API key missing or revoked. |
| 403 | — | Balance too low, or the token has no access to gpt-4o-mini-tts. |
| 503 | model_not_found | No available channel for the model in your group. |
FAQ
Frequently asked questions
How is billing calculated?
Input text is $0.9 per million tokens and generated audio is $31.5 per million audio tokens. One minute of speech is about 1 000 audio tokens, so it costs roughly $0.03 to $0.04.
Which audio formats can I request?
Set response_format to mp3 (default), opus, aac, wav or pcm.
How do I control tone and style?
Pass a plain-language sentence in instructions, for example “Speak slowly and warmly.” Pair it with a voice such as coral or sage.
How long can the input be?
Up to 4 096 characters per request. For longer text, split it at sentence boundaries, send several requests and join the audio.
Can I stream the audio?
Yes. Set stream_format to sse and read the Server-Sent Events as they arrive.
Why is the response body empty in Postman?
The response is binary audio, not text, so the body panel shows nothing. Use Send and Download (or Save Response) to write it to an .mp3 file.