Skip to content

Text-to-Speech

POST /v1/audio/speech

OpenAI-compatible text-to-speech. Returns raw audio bytes (mp3, wav, or opus). Drop-in compatible with the OpenAI client.audio.speech.create() API.

FieldTypeDefaultDescription
modelstring"auto"TTS model (see Providers). Use "auto" for health-aware routing.
inputstringrequiredText to speak. 1–10,000 chars.
voicestring"alloy"One of alloy, echo, fable, onyx, nova, shimmer (Workers AI MeloTTS).
response_formatstring"mp3"One of "mp3", "wav", "opus", "flac". Actual formats served depend on provider.
speednumber1.0Playback speed multiplier, 0.25–4.0. Honoured by providers that expose it.
project_idstringBody-level project tag. Alternative to x-gateway-project-id header.
HeaderRequiredDescription
Authorization: Bearer <GATEWAY_API_KEY>yesGateway API key.
x-gateway-project-idyes (or body project_id)1–64 chars [a-zA-Z0-9._:-].
x-gateway-force-providernoPin to workers_ai or groq.
ProviderModelVoicesStatus
Cloudflare Workers AI@cf/myshell-ai/melottsalloy, echo, fable, onyx, nova, shimmerEnabled — no external key, uses Workers AI binding.
Groq PlayAIplayai-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.

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

FormatContent-Type
mp3audio/mpeg
wavaudio/wav
opusaudio/opus

Response Headers:

HeaderDescription
x-gateway-providerProvider that served the request (e.g. workers_ai).
x-gateway-modelExact model used.
x-gateway-project-idEchoes the resolved project id.
Terminal window
curl https://free-ai-gateway.sarthakagrawal927.workers.dev/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
StatuscodeMeaning
400invalid_project_idMissing/invalid project_id.
502provider_errorAll TTS candidates failed. Last upstream error is included in the message.
503no_tts_providerNo TTS binding/key configured.