Swagger Petstore - OpenAPI 3.0
POST/audio/speech

Generate audio from text

Generates audio from input text using a text-to-speech model. Supply model, input text, and voice at minimum — response_format defaults to mp3 and speed defaults to 1.0. Returns the audio file content or a stream of audio events depending on the stream_format parameter.

  • IdempotentThe SDK sends Idempotency-Key, so a retried request is only applied once.

7 body fields

Text-to-speech configuration. model, input, and voice are required.

modelstringrequired
One of the available [TTS models](/docs/models#tts): `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](/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

2 status codes
200Returns the audio file content in the specified format, or a stream of audio events if streaming is enabled.
429Returned when the request rate limit is exceeded.
errorobjectrequired

Error handling

model is required and must be one of: tts-1, tts-1-hd, gpt-4o-mini-tts, or gpt-4o-mini-tts-2025-12-15. input is required and must not exceed 4096 characters. voice is required and must be a built-in voice name or a custom voice object with an id. speed must be between 0.25 and 4.0. A 429 is returned when the request rate limit is exceeded.