Skip to content

SPEV: turn decisions up to 36% sooner. Details →

Text-to-speech API

Synthesize speech from a string with the OpenAI-compatible speech endpoint, including streaming and audio formats.

POST /v1/audio/speech follows the OpenAI speech shape. If you already call OpenAI for text to speech, change the base URL and the model.

model takes a text-to-speech model id from Models.

Synthesize speech

curl https://api.sprag.ai/v1/audio/speech \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $SPRAG_API_KEY" \
  -d '{
    "model": "chorus",
    "input": "The quarterly numbers are in and they look good.",
    "voice": "marin",
    "response_format": "mp3"
  }' \
  --output out.mp3

The response body is the audio itself, not JSON.

Request fields

FieldRequiredTypeNotes
modelYesstringA text-to-speech model id, such as chorus.
inputYesstringThe text to speak.
voiceNostringA preset id, or the id of a voice your organization created.
instructionsNostringStyle guidance on how the voice reads. Accepted for voices whose model supports it.
response_formatNostringmp3, opus, flac, wav, or pcm.
speedNonumberSpeaking rate multiplier, 0.25 to 4.0.
languageNostringOutput language. See languages.
stream_formatNostringsse or audio. Omit to receive the whole clip at once.
ref_audioNostringInline data: URL of reference audio, for cloning.
ref_textNostringTranscript of that reference audio.
temperatureNonumberSampling temperature, 0 to 2.
top_pNonumberNucleus sampling probability mass, 0 to 1.
top_kNointegerNumber of top candidates sampled from, 0 or greater.

Set response_format to the container the player or store on your side expects. Omit speed for the voice's natural rate, and omit temperature, top_p, and top_k for the model's default sampling.

Voices

GET /v1/audio/voices takes a model query parameter and lists its presets, followed by the voices your organization created.

curl "https://api.sprag.ai/v1/audio/voices?model=chorus" \
  -H "Authorization: Bearer $SPRAG_API_KEY"

To design or clone a voice, see Voices.

Streaming

Set stream_format to start playback before generation finishes.

stream_formatDelivery
omittedOne buffered response after generation finishes.
audioRaw chunked audio as it is generated.
ssespeech.audio.delta and speech.audio.done events.

Streaming is available with pcm and wav. Use pcm when the bytes feed another pipeline and wav when the far end requires a container. Audio formats covers the choice in full.

To speak many utterances over one connection, such as each sentence of a voice agent's reply, see Text to speech over a WebSocket.

Rate limits

Rate limits apply per organization. Rate limits has the headers and retry guidance.

Errors

StatusMeaning
400Validation error: an unknown voice, a field the voice's model does not accept, or a value outside an enum.
401Missing, invalid, or expired credentials.
402Out of credit. Also sent with the code payment_overdue when a plan invoice is unpaid. Also sent while billing for a new account is being set up; retry the request after a moment.
403Not a member of the requested organization.
404No model by that name.
413Request too large.
429Rate limit exceeded.