Speech (Text-to-Speech)
POST /v1/speech — synthesize spoken audio from text through the assigned route.
POST /v1/speech converts text into spoken audio. The assigned route must include a model with the audio_output capability.
For the reverse direction — turning audio into text — see Audio and STT.
Request
curl https://ai.latentkit.com/v1/speech \
-H "Authorization: Bearer $LATENTKIT_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"input": "Welcome to LatentKit. Your request was routed automatically.",
"voice": "alloy",
"response_format": "mp3",
"speed": 1.0
}'Fields
| Field | Description |
|---|---|
input | Text to synthesize (required) |
voice | Voice name when the route model supports voice selection (e.g. alloy) |
response_format | Output audio format when supported (e.g. mp3, wav, opus) |
speed | Playback speed multiplier when supported (must be greater than 0) |
response_profile | fast, balanced, or thinking when the route allows overrides |
Voice names and formats are provider-specific. Because the route decides which provider executes, prefer widely supported values, or pin a specific model in the routing policy when your product depends on one exact voice.
Provider field mapping
| OpenAI | ElevenLabs | |
|---|---|---|
voice | Voice name (alloy, nova, ...). Defaults to alloy. | Voice ID (e.g. 21m00Tcm4TlvDq8ikWAM). Defaults to the shared library voice. |
response_format | mp3, wav, opus, flac, aac, pcm | mp3, pcm, or a native token such as mp3_44100_128 / pcm_16000. Other values return 400 rather than silently substituting a different format. |
speed | Playback speed multiplier | Mapped to voice_settings.speed |
Do not send model (or any other route-control field) in the request body.
Routing is decided by the policy assigned to your API key; those fields are
ignored, and the model that executes is reported back as response.model.
SDK
const speech = await client.speech.create({
input: 'Welcome to LatentKit.',
voice: 'alloy',
response_format: 'mp3',
});speech = client.speech.create(
input="Welcome to LatentKit.",
voice="alloy",
response_format="mp3",
)Response
Speech responses use the unified runtime envelope (id, provider, model, policy_version_id, usage). The audio arrives as an output_audio block in content_blocks — base64 data plus its media type — not as a binary stream:
{
"provider": "elevenlabs",
"model": "eleven_flash_v2_5",
"content": "",
"content_blocks": [
{ "type": "output_audio", "base64": "SUQzBAAA...", "media_type": "audio/mpeg" }
],
"usage": { "audio_output_characters": 20 },
"cost_usd": 0.001
}To write a playable file:
curl -s https://ai.latentkit.com/v1/speech \
-H "Authorization: Bearer $LATENTKIT_API_KEY" \
-H "Content-Type: application/json" \
-d '{"input":"Welcome to LatentKit."}' \
| jq -r '.content_blocks[0].base64' | base64 -d > speech.mp3Speech is metered in characters of the input text, not tokens. A speech
request reports usage.audio_output_characters and total_tokens: 0 — that is
correct, not a missing value. Cost is characters x the model's per-character price.
ElevenLabs voice models
ElevenLabs is available for your own API key (BYOK) connections. Enable the models on the connection, then add them to the route your key resolves to.
| Model | Price | Notes |
|---|---|---|
eleven_flash_v2_5 | $0.05 / 1K characters | Lowest latency; good default for interactive speech |
eleven_turbo_v2_5 | $0.05 / 1K characters | Latency-optimised, quality between Flash and Multilingual |
eleven_multilingual_v2 | $0.10 / 1K characters | Higher-quality multilingual voice |
eleven_v3 | $0.10 / 1K characters | Latest generation voice model |
Your ElevenLabs API key must grant the Text to Speech permission, plus Models (read) so the connection health check can validate the credential. A key scoped without Text to Speech passes the health check and then fails on the first synthesis request.
Managed (Platform Access) routing for ElevenLabs is not enabled — these models
route through BYOK connections only, and usage is billed by ElevenLabs to your
own account. The cost_usd on a BYOK response is LatentKit's estimate of that
provider charge, not a workspace credit deduction.
Managed Billing
Platform Access speech consumes workspace credits when the selected model is available for managed usage. BYOK speech is charged by your provider account. Check current availability and pricing in the console.
Audio output inside chat
Chat requests can also request spoken output by including "modalities": ["audio"] when the route model supports audio output. When present, LatentKit requires the audio_output capability for route eligibility.
Troubleshooting
NO_HEALTHY_PROVIDERmeans no route model has theaudio_outputcapability. Enable a TTS-capable model on a connection and add it to the route. A healthy connection is not enough on its own — the model must also be in the published route.- A
400namingresponse_formatmeans the provider does not accept that format. See the field mapping above for the accepted values. total_tokens: 0alongside a non-zero charge is expected for speech: the billable unit is characters.- If a model is unavailable through Platform Access, use a supported BYOK connection or select another route model.
Related
- Audio and STT — transcription and translation
- Models & providers
- Routes & policies