LatentKit

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

FieldDescription
inputText to synthesize (required)
voiceVoice name when the route model supports voice selection (e.g. alloy)
response_formatOutput audio format when supported (e.g. mp3, wav, opus)
speedPlayback speed multiplier when supported (must be greater than 0)
response_profilefast, 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

OpenAIElevenLabs
voiceVoice name (alloy, nova, ...). Defaults to alloy.Voice ID (e.g. 21m00Tcm4TlvDq8ikWAM). Defaults to the shared library voice.
response_formatmp3, wav, opus, flac, aac, pcmmp3, pcm, or a native token such as mp3_44100_128 / pcm_16000. Other values return 400 rather than silently substituting a different format.
speedPlayback speed multiplierMapped 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.mp3

Speech 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.

ModelPriceNotes
eleven_flash_v2_5$0.05 / 1K charactersLowest latency; good default for interactive speech
eleven_turbo_v2_5$0.05 / 1K charactersLatency-optimised, quality between Flash and Multilingual
eleven_multilingual_v2$0.10 / 1K charactersHigher-quality multilingual voice
eleven_v3$0.10 / 1K charactersLatest 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_PROVIDER means no route model has the audio_output capability. 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 400 naming response_format means the provider does not accept that format. See the field mapping above for the accepted values.
  • total_tokens: 0 alongside 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.

On this page