Skip to content
OneAPIDocs
ModelsOpen console

API reference

Text to speech

OpenAI's speech request, answered with the audio itself. See the Voice guide for picking a voice.

POSThttps://api.oneapi.id/v1/audio/speech
Key header
Authorization: Bearer
Answer
The audio bytes, not JSON
Billed
Characters of input, at the input price

Body fields

modelstring required

A tts model from GET /v1/audio/models.

inputstring required

The text to speak.

voicestring

A voice id from /v1/audio/voices. Omit it for the model's default voice.

languagestring

A language hint such as id or en-GB. Without it the text is read as English.

response_formatstring

wav (default), pcm or opus.

sample_rateinteger

Hertz, 8000 to 192000. Default 24000, which every model offers.

provider_optionsobject

A vendor's own settings, keyed by vendor: {"elevenlabs":{"stability":0.4}}.

Example

Write the clip to a file
curl https://api.oneapi.id/v1/audio/speech \
  -H "Authorization: Bearer $ONEAPI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"model":"eleven_v4_turbo","input":"Halo.","language":"id"}' \
  --output speech.wav

Response formats

response_formatContent-TypeWhat you get
wavaudio/wav16-bit mono PCM in a WAV file, ready to play
pcmaudio/pcm;rate=24000The same samples with no header
opusaudio/opusOpus, on models that offer it

Errors

Errors use the standard shape. A 400 also covers a model that is not a speech model, a response_format of mp3, and a speed other than 1.