Speech
Last updated: 2026-11-24T12:31:51-03:00 (UTC-3)
POST /v1/audio/speech turns text into audio. The request is the OpenAI speech request (model, input, voice, and optionally response_format, speed and instructions); the answer is the provider’s audio. This page covers how a clip is delivered, what happens when it is cut, how it is charged, how to list voices, and the providers that serve it.
Turn it on
Section titled “Turn it on”Speech needs the audio_speech flag (on by default), an alias with the audio_speech capability and a key with the route:audio_speech scope.
features: audio_speech: trueproviders: - id: openai preset: openaimodels: - id: tts capabilities: [audio_speech] targets: [{provider: openai, model: tts-1}]curl -sS https://gateway.example.com/v1/audio/speech \ -H "Authorization: Bearer $GATEWAY_KEY" -H "Content-Type: application/json" \ -d '{"model":"tts","input":"Hello","voice":"alloy"}' -o hello.mp3Everything below this section is optional and off by default, each part behind its own flag:
| Flag | What it enables |
|---|---|
speech_buffer |
speech.delivery: buffer on an alias: whole clips only |
speech_voices |
GET /v1/audio/voices |
speech_polly |
Amazon Polly targets |
speech_azure |
Azure AI Speech targets |
speech_gemini |
Gemini text to speech targets |
All five need audio_speech. They are operator controls: set them in the YAML, with PUT /api/v1/admin/features/{id}, or on the console’s Feature flags page.
How a clip is delivered
Section titled “How a clip is delivered”The gateway sends each piece of audio to the client as soon as the provider produces it, so playback can start before the clip is complete. Measured with a stand-in provider that sends a 3.0 s clip in 20 pieces, and the request log on PostgreSQL, the client’s first byte arrives within 10 ms of the provider’s; before this behaviour existed it arrived at 2.4 s, with most of the clip.
The answer has no Content-Length: it is chunked on HTTP/1.1 and a plain stream on HTTP/2. Nothing needs to be set, and stream in the request body is passed to the provider as it is.
When a clip is cut
Section titled “When a clip is cut”Three things can stop a clip after it started. The status is already 200 by then, so each is told another way:
| What happened | What the client sees | Request log and request event | Provider error count and circuit breaker |
|---|---|---|---|
| The provider cut the clip | The connection is aborted: an unterminated chunked body on HTTP/1.1, a stream reset on HTTP/2. curl exits with an error; an HTTP library raises one |
status 200, error_code: stream_interrupted, truncated: true |
counted (gateway_provider_errors_total{class="stream_interrupted"}), one failure of the destination |
| The client hung up | Nothing: it left | status 200, error_code: client_closed_stream, truncated: true; the log line stream_copy_failed with side: client |
not counted |
| The gateway was stopped | The connection is aborted | status 200, error_code: stream_aborted |
not counted |
A clip that fails before its first byte has put nothing on the wire, so the client gets a plain error instead: 502 with the code stream_interrupted, recorded and counted as above with that status.
A cut clip is never ended as if it were complete: a client that checks for a transport error cannot take part of a clip for a whole one. A cut clip is a failure everywhere a failure is counted (the request log’s error filter, analytics, the error rate, spans and their OTLP export), exactly as a cut text stream is. Each record carries the key, principal, team and organization of the request, and reads are filtered by the reader’s teams and organization.
When the client hangs up, the gateway cancels the provider call instead of reading the rest of the clip.
Once audio has started the request is never sent to another target or retried: the client already has part of an answer.
How a clip is charged
Section titled “How a clip is charged”A provider that prices speech by the characters of the request (OpenAI tts-1, ElevenLabs, Amazon Polly, Azure AI Speech) charges the whole request once it accepts it, whether or not the clip reaches its end. The gateway charges the same way: from the first audio byte, the request costs its full per-character price, including when the provider cut the clip and when the client hung up. With durable receipts the receipt is settled, not left unknown.
Three cases stay unknown, never zero and never estimated:
- the provider answered
200and cut the clip before any audio byte; - a buffered clip answered as an error (
502, or499when the client left): the gateway values only requests that succeeded. A per-character provider has charged such a clip all the same, so read these rows as spend not yet priced, and usestreamwhere every cut clip must carry its cost; - a clip priced by tokens (Gemini) that was cut: the tokens are reported only at its end.
The characters counted are those of input; Amazon Polly reports the count it billed (x-amzn-RequestCharacters) and that count is used instead.
A per-character price comes from the price catalog, or from the price book:
price_book: - provider_id: openai model_id: tts-1 unit: per_character unit_price: "0.000015" source_url: https://openai.com/api/pricing/ effective_from: "2026-01-01T00:00:00Z"Whole clips only
Section titled “Whole clips only”Some clients cannot use part of a clip: they store the file, or play it only when complete. For them an alias can hold the answer until the provider finished the clip.
features: speech_buffer: truemodels: - id: tts-whole capabilities: [audio_speech] speech: delivery: buffer buffer_max_mib: 32 targets: [{provider: openai, model: tts-1}]| Field | Default | Bounds | Meaning |
|---|---|---|---|
models[].speech.delivery |
stream |
stream, buffer |
buffer delivers only whole clips. Read only while speech_buffer is on; with the flag off the alias streams |
models[].speech.buffer_max_mib |
32 |
1 to 256 | The largest clip kept in memory while it arrives, per request |
With buffer:
- a whole clip is answered with its
Content-Length, after the provider’s last byte. The client waits for the whole clip before its first byte: choose this only when part of a clip is useless; - a clip the provider cut is answered
502with the codestream_interrupted, and no audio byte. It is counted as a provider error and as one failure of the destination, and its cost is recorded as unknown (how a clip is charged); - a clip longer than
buffer_max_mibis answered502with the codespeech_buffer_exceeded. Raise the limit, or usestream; - a client that hangs up while the clip arrives cancels the provider call, and the request is recorded with status
499.
Size the limit for your longest clip and your concurrency: each buffered request holds its clip in memory, up to the limit. One minute of MP3 at 128 kbit/s is about 1 MiB; one minute of 24 kHz PCM is about 2.8 MiB.
The setting is per alias, so one deployment can stream on one alias and buffer on another with the same provider. It is set in the YAML, in the alias sent to PUT /api/v1/admin/models/{id}, or in the console’s model editor under Speech. It is refused on an alias without the audio_speech capability, on an auto route and on an alias_of entry. A change applies to the next request, with no restart.
Voice discovery
Section titled “Voice discovery”GET /v1/audio/voices lists the voices of the speech aliases a key may use, with the provider and provider model each voice belongs to. Add ?model=<alias> for one alias.
features: speech_voices: truecurl -sS "https://gateway.example.com/v1/audio/voices?model=tts" -H "Authorization: Bearer $GATEWAY_KEY"{ "object": "list", "data": [ {"id": "alloy", "model": "tts", "provider": "openai", "source": "built_in"}, {"id": "Joanna", "name": "Joanna", "model": "tts-polly", "provider": "polly", "languages": ["en-US"], "gender": "female", "source": "provider"} ], "unavailable": [ {"model": "tts-local", "provider": "kokoro", "reason": "unknown_model"} ]}Send a voice’s id as voice on /v1/audio/speech. provider is the connection ID, the value of X-Gateway-Provider on an answer. Each entry also has provider_model, the target’s model, only when the operator shows it on inference answers (server.response_headers.served_target: true, response headers); by default a key learns the connection and not the model behind the alias.
Where each list comes from, in this order:
source |
Used for | Where it comes from |
|---|---|---|
declared |
Any alias with speech.voices |
The alias’s own list. Use it for a self-hosted speech server, or to show a subset |
provider |
ElevenLabs, Amazon Polly, Azure AI Speech | The provider’s voice list, read with the connection’s credential. Polly is asked for the voices of the target’s engine. The credential must be allowed to list voices: an ElevenLabs key needs the voices_read permission, an AWS identity polly:DescribeVoices; without it the target is provider_unavailable |
built_in |
OpenAI tts-1, tts-1-hd, gpt-4o-mini-tts; Gemini |
The voices the provider documents for the model. These providers have no route that lists them |
models: - id: tts-local capabilities: [audio_speech] speech: voices: [af_heart, bm_george] targets: [{provider: kokoro, model: kokoro}]models[].speech.voices takes up to 256 unique names of 1 to 128 letters, digits, dots, underscores, colons or hyphens.
A target that cannot be listed is in unavailable with a reason: unknown_model (no list exists for the model: declare speech.voices), provider_disabled (the flag of the target’s speech provider is off) or provider_unavailable (the provider’s list could not be read; the next request tries again).
What to know:
- The key needs the
route:audio_speechscope, and sees only aliases it may use. An alias it may not use, one that does not serve speech and one that does not exist all answer404 model_not_found. - A provider’s list is kept in memory for five minutes on each replica. A new voice at the provider appears after at most that long. A list that could not be read is remembered for 30 seconds, so a provider that is down is not called by every request; one listing waits 10 seconds at most, whatever its number of targets.
- The listing is not an inference request: nothing is charged, and no request log row is written. The request line in the log carries the key, principal, team and organization.
- Listing a voice grants nothing. The speech route applies its own checks to every request.
- In the console, the Playground’s Speech tab suggests the alias’s voices when
speech_voicesis on and a typed gateway key is in use; any voice name can still be typed.
Providers
Section titled “Providers”| Provider | Protocol | Flag | Target model |
voice |
response_format |
speed |
Priced by |
|---|---|---|---|---|---|---|---|
| OpenAI and compatible servers | openai |
audio_speech |
The speech model | The provider’s | Passed through | Passed through | Characters |
| ElevenLabs | elevenlabs |
audio_speech |
The model ID | A voice ID | mp3, opus, pcm |
0.7 to 1.2 | Characters |
| Amazon Polly | polly |
speech_polly |
The engine | A Polly voice ID | mp3, opus |
Refused | Characters Polly bills |
| Azure AI Speech | azure_speech |
speech_azure |
Your name for the price tier | A voice short name | mp3, opus, pcm, wav |
0.5 to 2 | Characters |
| Gemini | gemini |
speech_gemini |
The TTS model | A prebuilt voice | pcm, wav |
Refused | Tokens |
instructions is passed through on openai targets, becomes the spoken direction on Gemini, and is refused on ElevenLabs, Amazon Polly and Azure AI Speech.
The request is always the OpenAI one. A member the provider has no equivalent for is refused with 422 unsupported_on_provider before anything is sent, never dropped or approximated. A target whose flag is off answers 404 feature_disabled.
An alias on polly or azure_speech serves audio_speech and nothing else. On gemini, an alias with audio_speech as its only capability is a speech alias.
Amazon Polly
Section titled “Amazon Polly”Polly’s SynthesizeSpeech, signed with SigV4 for the polly service. The target’s model is the engine: standard, neural, long-form or generative.
features: speech_polly: trueproviders: - id: polly protocol: polly base_url: https://polly.us-east-1.amazonaws.com auth: {type: aws_sigv4, region: us-east-1}models: - id: tts-polly capabilities: [audio_speech] targets: [{provider: polly, model: neural}]- The base URL must be
https://polly.<region>.amazonaws.com(.amazonaws.com.cnin the China regions; the FIPS hosts are accepted), andauth.regionmust be that region: a signature is sent to no other host. Credentials come from the usual AWS chain (provider credentials); the identity needspolly:SynthesizeSpeech, andpolly:DescribeVoicesfor voice discovery. voiceis a Polly voice ID such asJoannaorCamila. Not every voice has every engine; Polly refuses a pair it does not have.inputis 1 to 3,000 characters, sent as plain text (not SSML).response_formatismp3(default) oropus(Ogg Opus).pcmis refused: Polly’s PCM is 8 or 16 kHz and OpenAI’s is 24 kHz.- Prices differ per engine: give each engine its own price book entry, with
model_idthe engine.
Azure AI Speech
Section titled “Azure AI Speech”The Speech service’s text to speech REST API. The gateway builds the SSML from input, voice and speed.
features: speech_azure: trueproviders: - id: azure-speech protocol: azure_speech base_url: https://eastus.tts.speech.microsoft.com api_key_env: AZURE_SPEECH_KEY auth: {type: header, header: Ocp-Apim-Subscription-Key}models: - id: tts-azure capabilities: [audio_speech] targets: [{provider: azure-speech, model: neural}]- The base URL is your region’s endpoint, or your resource’s custom domain. The resource key goes in
Ocp-Apim-Subscription-Key. A bearer token is also accepted (auth.type: bearer), but Azure’s tokens last ten minutes and the gateway does not renew them: use the key unless you rotate the token yourself. voiceis a voice short name such asen-US-AvaMultilingualNeuralorpt-BR-FranciscaNeural. Its first two parts are the language of the SSML.inputis spoken as plain text: markup in it is escaped, not interpreted.response_format:mp3(default; 24 kHz, 48 kbit/s),opus(Ogg, 24 kHz),pcm(raw 24 kHz 16-bit mono) orwav(the same PCM in a RIFF file).speedfrom 0.5 to 2 becomes the prosody rate.- Azure has no model parameter: the voice decides the tier. The target’s
modelis the name you price by; use one alias per tier (for exampleneuralandneural-hd) when their prices differ.
Gemini
Section titled “Gemini”Gemini’s speech generation on the Gemini API (not on Vertex AI). The gateway asks for a streamed answer and relays the audio as it arrives.
features: speech_gemini: trueproviders: - id: gemini preset: geminimodels: - id: tts-gemini capabilities: [audio_speech] targets: [{provider: gemini, model: gemini-2.5-flash-preview-tts}]curl -sS https://gateway.example.com/v1/audio/speech \ -H "Authorization: Bearer $GATEWAY_KEY" -H "Content-Type: application/json" \ -d '{"model":"tts-gemini","input":"Hello","voice":"Kore","response_format":"wav"}' -o hello.wavresponse_formatis required and must bepcmorwav. Gemini returns 24 kHz 16-bit mono PCM and the gateway does not transcode;mp3, the OpenAI default, is refused.pcmis the raw samples (audio/pcm;rate=24000), the same format as OpenAI’spcm.wavis those samples behind a RIFF header whose sizes are the maximum value, as in any streamed WAV file; players accept it, and a tool that needs exact sizes should takepcm.voiceis one of Gemini’s 30 prebuilt voices, such asKoreorPuck; voice discovery lists them.- The text is sent as
Say: <input>, the form Gemini’s speech models are prompted in: given a bare short text, the model treats it as a message to answer and refuses the request. Withinstructions, they replaceSayas the direction ("instructions": "Speak slowly and warmly"sendsSpeak slowly and warmly: <input>); up to 1,000 characters. The direction is part of the prompt Gemini bills. speedis refused; describe the pace ininstructions. One speaker per request.- The clip is charged by the tokens Gemini reports at its end, at the model’s input and output prices (the output price of a TTS model is its audio price). The request log shows both counts. A cut clip has no usage, so its cost is unknown.
- A text Gemini refuses to speak (a blocked prompt, a safety stop) is answered
422with the codespeech_refusedwhen no audio was sent yet. It is the request’s outcome: no provider error is counted and the circuit of the destination is untouched. A clip Gemini stops for its content after it started is aborted like a cut clip and recorded witherror_code: stream_aborted, also without blaming the destination. - A stream that fails before any audio is answered
502, counted as a provider failure, and the alias’s next target is tried when there is one. A stream that ends without Gemini’sSTOP, or with an error event, after audio started is a cut clip. - With
speech.delivery: buffer, awavclip carries its real sizes.
Limits
Section titled “Limits”- The gateway does not convert audio formats or sample rates.
- Speech requests take no part in token budgets; their cost is in the request log and the cost reports.
- The Playground lists voices only with a typed gateway key; with the console session it suggests OpenAI’s voices and accepts any typed name.