Skip to content

Create speech

Turn text into speech. OpenAI compatible, streamed audio, with the cost in a response header.

Markdown
On this page
POST/v1/audio/speech

Turns input into audio and streams it back as it is produced. The request is OpenAI compatible, so audio.speech.create in the OpenAI SDKs works against this endpoint. Walkthrough: Speech and voices.

Request body

modelstringrequired

A speech model id (for example openai/gpt-4o-mini-tts) or a preset such as @tts. List speech models with GET /models?kind=speech.

inputstringrequired

The text to speak, up to the model's speech.maxInputChars.

voicestringrequired

A voice id from GET /audio/voices: a ready-made voice or one of the project's clones (lvc_…).

response_formatstring

mp3 (default), opus, aac, flac, wav or pcm, as the model allows (speech.formats).

speednumber

Within the model's speech.speed range.

languagestring

The language of input, for models that take it.

instructionsstring

A speaking style, for models with speech.instructions.

provider_optionsobject

Provider-specific options from the model's allow-list.

userstring

and metadata (object) — Tags stored with the request record and never sent to the provider.

Example

curl https://api.getlykia.com/v1/audio/speech \
  -H "Authorization: Bearer $LYKIA_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "openai/gpt-4o-mini-tts",
    "input": "Your order has shipped and will arrive on Thursday.",
    "voice": "alloy",
    "response_format": "mp3"
  }' \
  --output speech.mp3

Response

The body is the audio, with a Content-Type that matches the format (audio/mpeg for mp3). Headers:

HeaderMeaning
X-Generation-IdThe request id.
X-Lykia-CostThe cost in USD. It is known before the audio starts, from the length of input (or the token estimate).
X-Lykia-PresetThe preset's name, when model was a preset.

If the connection drops while the audio is streaming, the characters the provider has billed are still charged.

Errors

StatusCodeWhen
400unsupported_inputAn unsupported response_format, speed or option, or input longer than the model takes (metadata.param).
400unsupported_modelThe model does not make speech.
403platform_sales_disabledThe provider is not offered on Lykia credits yet; add your own key for it.
404voice_not_foundThe voice id is unknown or belongs to another project.
429provider_busyLykia's connection to the provider is at its limit of requests at once; retry after Retry-After.