Skip to content

Text-to-Speech

POST /v1/audio/speech

OpenAI-compatible text-to-speech. Returns MP3 audio bytes. Uses the request shape of the OpenAI client.audio.speech.create() API.

Field Type Default Description
model string "auto" TTS model (see Providers). Use "auto" for health-aware routing.
input string required Text to speak. 1–3,000 chars; the shared daily budget may reject shorter requests.
voice string "luna" luna; legacy alloy, echo, fable, onyx, nova, shimmer are aliases for the same Luna voice.
response_format string "mp3" Workers AI supports "mp3" only; other formats are rejected before inference.
speed number 1.0 Workers AI supports 1.0 only; other values are rejected before inference.
project_id string — Body-level project tag. Alternative to x-gateway-project-id header.
Header Required Description
Authorization: Bearer <GATEWAY_API_KEY> yes Gateway API key.
x-gateway-project-id yes (or body project_id) 1–64 chars [a-zA-Z0-9._:-].
x-gateway-force-provider no Pin to workers_ai or groq.
Provider Model Voices Status
Cloudflare Workers AI @cf/deepgram/aura-2-en luna (plus the legacy aliases above) Enabled — no external key, uses Workers AI binding.
Groq PlayAI playai-tts — :warning: Disabled — Groq deprecated playai-tts on their free tier. Kept in the registry for future re-enablement but currently returns no_tts_provider.

Aura 2 uses a character-based price. The gateway conservatively reserves against UTF-8 byte length plus a 20% buffer before inference, within the shared 9,500 Neurons/day cap. At the published rate, 1,000 ASCII characters reserve 3,273 Neurons. A 3,000-character request can therefore exceed the whole daily cap. See Cloudflare pricing.

Binary audio bytes. The Content-Type matches the served format:

Format Content-Type
mp3 audio/mpeg

Response Headers:

Header Description
x-gateway-provider Provider that served the request (e.g. workers_ai).
x-gateway-model Exact model used.
x-gateway-project-id Echoes the resolved project id.
Terminal window
curl https://ai-gateway.sassmaker.com/v1/audio/speech \
-H "Authorization: Bearer <GATEWAY_API_KEY>" \
-H "x-gateway-project-id: my_project" \
-H "Content-Type: application/json" \
-d '{
"model": "auto",
"input": "Hello world. This is the free AI gateway speaking.",
"voice": "nova",
"response_format": "mp3"
}' \
--output speech.mp3
Status code Meaning
400 invalid_project_id Missing/invalid project_id.
502 provider_error All TTS candidates failed. Last upstream error is included in the message.
503 no_tts_provider No TTS binding/key configured.