Text to speech
OpenRouter's text-to-speech API: one text in, the whole audio out as MP3 or raw PCM, never streamed. A call bills the input's characters, and settles before the first byte is sent. The answer has no JSON body, so its cost is in the generation record that X-Generation-Id names. GET /api/v1/models?output_modalities=speech lists the models your key can call, each with its supported_voices, default_voice and speech_speed.
curl -X POST https://api.llm.buzz/api/v1/audio/speech \
-H "Authorization: Bearer $LLM_BUZZ_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "hexgrad/kokoro-82m",
"input": "Your order has shipped.",
"voice": "af_heart",
"response_format": "mp3"
}'{
"error": {
"code": 400,
"message": "...",
"metadata": {
"error_type": "invalid_request",
"gateway_code": "invalid_request",
"param": "messages"
}
}
}{
"error": {
"code": 401,
"message": "A valid gateway Bearer key is required. Send the virtual key as 'Authorization: Bearer <key>'.",
"metadata": {
"error_type": "authentication",
"gateway_code": "invalid_key"
}
}
}{
"error": {
"code": 402,
"message": "...",
"metadata": {
"error_type": "payment_required",
"gateway_code": "insufficient_credits"
}
}
}{
"error": {
"code": 404,
"message": "The requested model does not exist or is not granted to this key. GET /api/v1/models lists the model aliases available to this key.",
"metadata": {
"error_type": "not_found",
"gateway_code": "model_not_found",
"param": "model"
}
}
}Authorization
An inference key, as Authorization: Bearer KEY.
Body application/json
modelstringrequiredA text-to-speech model from
GET /api/v1/models?output_modalities=speech, such ashexgrad/kokoro-82m.inputstringrequired1 to 4,096 characters. An array of turns (several speakers) is a 400.
voicestringOne of the model's
supported_voices; omitted, itsdefault_voice.response_formatstringpcm(the default: signed 16-bit little-endian mono) ormp3.pcmmp3speednumber0.25 to 4.0, on a model whose
speech_speedistrue.providerobjectThe audio routes read only the data policy fields;
order,only,ignore,allow_fallbacksandsortare accepted and ignored. With the OpenAI SDK, send it inextra_body.Show 2 child fields
zdrbooleantruekeeps the request on providers that declare 0 days of retention.data_collectionstringdenykeeps the request on providers that declare no training and 0 days of retention.allowdeny
Response 200
The audio: audio/mpeg, or audio/pcm at the provider's rate, with Cache-Control: no-store and the X-Generation-Id header.
Errors
400A field is missing or malformed (
invalid_request, withmetadata.param), or the model cannot do what the request asks (unsupported_capability).401No key, or the key is unknown, expired, revoked or disabled.
402Your balance is spent and the model is not free, or the request could cost more than your balance.
404No model has this name, or your key may not call it.