Sample - OpenAI API
POST/audio/speech

Create speech audio

Generates audio from input text using a selected text-to-speech model and voice. Supply model, input, and voice, then use response_format, speed, or stream_format to control the audio output. The response can contain an audio file or streamed audio events.

  • RetriesRetries up to 2×, 500ms backoff, 30s timeout.

7 body fields

Text-to-speech configuration specifying the source text, model, voice, output format, speed, and streaming mode.

modelstringrequired
One of the available [TTS models](https://developers.openai.com/api/docs/guides/text-to-speech): `tts-1`, `tts-1-hd`, `gpt-4o-mini-tts`, or `gpt-4o-mini-tts-2025-12-15`.
inputstringrequired
The text to generate audio for. The maximum length is 4096 characters.
instructionsstringoptional
Control the voice of your generated audio with additional instructions. Does not work with `tts-1` or `tts-1-hd`.
voicestringrequired
The voice to use when generating the audio. Supported built-in voices are `alloy`, `ash`, `ballad`, `coral`, `echo`, `fable`, `onyx`, `nova`, `sage`, `shimmer`, `verse`, `marin`, and `cedar`. You may also provide a custom voice object with an `id`, for example `{ "id": "voice_1234" }`. Previews of the voices are available in the [Text to speech guide](https://developers.openai.com/api/docs/guides/text-to-speech#voice-options).
response_formatstringoptional
The format to audio in. Supported formats are `mp3`, `opus`, `aac`, `flac`, `wav`, and `pcm`.
Allowed:mp3opusaacflacwavpcmDefault:mp3
speednumberoptional
The speed of the generated audio. Select a value from `0.25` to `4.0`. `1.0` is the default.
Default:1
stream_formatstringoptional
The format to stream the audio in. Supported formats are `sse` and `audio`. `sse` is not supported for `tts-1` or `tts-1-hd`.
Allowed:sseaudioDefault:audio

3 status codes
200Returns binary audio content or a stream of speech events containing audio chunks and a completion event with usage information.
429Returned when the request was rejected because the rate limit was exceeded; reduce the request rate if a `slow_down` error is reported.

One documented failure

  • slow_down

    Your request rate increased too quickly. Please reduce the request rate and gradually increase it again.

    Traffic increased too quickly

errorobjectrequired
503Returned when the service is temporarily unavailable or the requested model is overloaded; retry after a brief delay.

One documented failure

  • server_is_overloaded

    The model is temporarily overloaded. Please retry your request after a brief delay.

    The requested model is temporarily overloaded

errorobjectrequired

Error handling

A 429 is returned when the request exceeds the rate limit, and a 503 is returned when the service or requested model is temporarily unavailable. model, input, and voice are required; input and instructions must be at most 4096 characters, speed must be between 0.25 and 4, and stream_format must be sse or audio.