Create speech
Turn text into speech. OpenAI compatible, streamed audio, with the cost in a response header.
MarkdownOn this page
/v1/audio/speechTurns 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
modelstringrequiredA speech model id (for example openai/gpt-4o-mini-tts) or a preset such as @tts. List speech models with GET /models?kind=speech.
inputstringrequiredThe text to speak, up to the model's speech.maxInputChars.
voicestringrequiredA voice id from GET /audio/voices: a ready-made voice or one of the project's clones (lvc_…).
response_formatstringmp3 (default), opus, aac, flac, wav or pcm, as the model allows (speech.formats).
speednumberWithin the model's speech.speed range.
languagestringThe language of input, for models that take it.
instructionsstringA speaking style, for models with speech.instructions.
provider_optionsobjectProvider-specific options from the model's allow-list.
userstringand 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.mp3import os
from openai import OpenAI
client = OpenAI(base_url="https://api.getlykia.com/v1", api_key=os.environ["LYKIA_API_KEY"])
with client.audio.speech.with_streaming_response.create(
model="openai/gpt-4o-mini-tts",
input="Your order has shipped and will arrive on Thursday.",
voice="alloy",
response_format="mp3",
) as response:
# The cost is known before the audio starts, so it comes as a header
print("cost (USD):", response.headers.get("X-Lykia-Cost"))
response.stream_to_file("speech.mp3")import { writeFile } from "node:fs/promises";
const response = await fetch("https://api.getlykia.com/v1/audio/speech", {
method: "POST",
headers: { Authorization: `Bearer ${process.env.LYKIA_API_KEY}`, "Content-Type": "application/json" },
body: JSON.stringify({
model: "openai/gpt-4o-mini-tts",
input: "Your order has shipped and will arrive on Thursday.",
voice: "alloy",
response_format: "mp3",
}),
});
if (!response.ok) throw new Error(`Lykia returned ${response.status}: ${await response.text()}`);
// The cost is known before the audio starts, so it comes as a header
console.log("cost (USD):", response.headers.get("X-Lykia-Cost"), "id:", response.headers.get("X-Generation-Id"));
await writeFile("speech.mp3", Buffer.from(await response.arrayBuffer()));Response
The body is the audio, with a Content-Type that matches the format (audio/mpeg for mp3). Headers:
| Header | Meaning |
|---|---|
X-Generation-Id | The request id. |
X-Lykia-Cost | The cost in USD. It is known before the audio starts, from the length of input (or the token estimate). |
X-Lykia-Preset | The 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
| Status | Code | When |
|---|---|---|
400 | unsupported_input | An unsupported response_format, speed or option, or input longer than the model takes (metadata.param). |
400 | unsupported_model | The model does not make speech. |
403 | platform_sales_disabled | The provider is not offered on Lykia credits yet; add your own key for it. |
404 | voice_not_found | The voice id is unknown or belongs to another project. |
429 | provider_busy | Lykia's connection to the provider is at its limit of requests at once; retry after Retry-After. |