API
API overview
Create speech
HTTP delivery
WebSocket streaming
Errors and limits

HTTP delivery

POST /v1/audio/speech supports raw audio streaming, SSE streaming, and buffered audio.

Stream raw audio

Set stream to true and stream_format to audio. The response body contains chunked audio bytes.

curl --no-buffer https://api.teenage.works/v1/audio/speech \
  -H "Authorization: Bearer tw_live_..." \
  -H "Content-Type: application/json" \
  -d '{"input":"Start playback as audio arrives.","language":"en","response_format":"mp3","stream":true,"stream_format":"audio"}' \
  --output speech.mp3
FormatContent type
pcmaudio/L16;rate={sample_rate};channels=1
mp3audio/mpeg

Stream SSE events

Set stream_format to sse. Each audio.delta contains a base64 audio chunk; the final audio.done reports the number of chunks.

text

event: audio.delta
data: {"type":"audio.delta","index":0,"delta":"<base64>","ttfa_ms":123.45}

event: audio.done
data: {"type":"audio.done","chunks":12}

ttfa_ms appears only on the first delta.

Buffer the response

Set stream to false to receive the complete audio body.

FormatContent type
pcmaudio/L16;rate={sample_rate};channels=1
mp3audio/mpeg
wavaudio/wav

Response headers

HeaderMeaning
x-request-idUnique request identifier
x-teenageworks-languageCanonical language code used
x-teenageworks-representationText representation sent to the model
x-teenageworks-sample-rateOutput sample rate
x-teenageworks-qualityApplied quality profile
x-teenageworks-generation-msTotal generation time on buffered responses
cache-controlno-store
Stream text over one WebSocket