AniwaffleDocsHomeStudio

API reference

Stream speech

A WebSocket endpoint that takes text in segments and returns audio chunks while generation runs. One connection carries one request.

Connect

WSSwss://aniwaffle.com/v1/tts/stream

Authenticate the handshake with one of:

CredentialHow to send itUse from
API keyAuthorization: Bearer awp_... headerYour server
Stream token?token=... query parameter, or the Authorization headerBrowsers and mobile apps. See Create a stream token.

A rejected credential or browser origin fails the handshake with HTTP 401. All messages are JSON text frames of at most 64 KiB. Audio is returned base64-encoded inside JSON events.

For a walkthrough with complete clients, see Streaming.

Message flow

DirectionEventWhen
Client → serverstartExactly once, first.
Client → servertextOne or more times.
Client → serverflushOptional, between text events.
Client → serverstopExactly once, last.
Server → clientaudioZero or more times, in order.
Server → clientusageOnce, after the last audio event.
Server → clientfinishOnce, last, on success.
Server → clienterrorOnce, last, on failure. Replaces finish.

Valid client order: start → text… → (flush → text…)… → stop. After finish or error, the request is over; open a new connection for the next one.

start

Configures the request. Send it once, before any text.

json
{
  "event": "start",
  "request": {
    "voice_id": "YOUR_VOICE_ID",
    "output_format": "pcm_48000",
    "context_id": "assistant_turn_7"
  }
}
FieldTypeRequiredDescription
request.voice_idstringYesA voice ID from GET /v1/voices.
request.output_formatstringYesOne of pcm_24000, pcm_44100, pcm_48000, aac_44100_128. Must be supported by the model.
request.modelstringNoA model ID from GET /v1/models. Defaults to Waffle Mono.
request.realtimebooleanNoUse the realtime tier. Defaults to false.
request.context_idstringNoYour identifier for this utterance, up to 200 characters. Echoed on audio events.
request.partner_session_idstringNoYour identifier for the conversation or session, 1–200 characters.

Don't send a request ID; the server assigns one and returns it on every event.

text

Appends text to the request. Segments are joined exactly as sent, so include spaces and punctuation between them.

json
{ "event": "text", "text": "Your order is ready, " }
FieldTypeRequiredDescription
textstringYes1–5,000 characters. All text events in a request total at most 20,000 characters, including tags.

flush

Generates the text received so far and keeps the request open for more. A flush with no pending text does nothing.

json
{ "event": "flush" }

stop

Generates any remaining text and ends the request. No more client events are accepted.

json
{ "event": "stop" }

audio

A chunk of generated audio.

json
{
  "event": "audio",
  "request_id": "rq_0f8c2d4e-...",
  "context_id": "assistant_turn_7",
  "seq": 1,
  "format": "pcm_48000",
  "audio": "AAABAAIA..."
}
FieldTypeDescription
request_idstringThe request's ID.
context_idstringYour context_id, when you sent one.
seqintegerChunk number, starting at 1 and increasing across flushes.
formatstringThe delivered format. Use it to choose the decoder.
channelsinteger2 for stereo. Absent for mono.
audiostringBase64-encoded audio bytes.

usage

Totals for the request, sent once after the last chunk.

json
{
  "event": "usage",
  "request_id": "rq_0f8c2d4e-...",
  "voice_id": "YOUR_VOICE_ID",
  "usage": { "chars": 48, "audio_ms": 2760 }
}
FieldTypeDescription
usage.charsintegerCharacters generated.
usage.audio_msintegerLength of the generated audio in milliseconds.
voice_idstringThe voice used.

finish

The final event of a successful request. The server closes the connection with code 1000 afterwards.

json
{
  "event": "finish",
  "request_id": "rq_0f8c2d4e-...",
  "reason": "stop",
  "cost": { "credits": 48, "amount": 0.00021, "currency": "USD", "settlement_status": "settled" },
  "audit_id": "rq_0f8c2d4e-...",
  "audio_persisted": true
}
FieldTypeDescription
reasonstringstop when the request completed normally.
cost.creditsnumberCredits charged for the request.
cost.amountnumberThe credits' value in cost.currency.
cost.settlement_statusstringsettled, or pending while the final charge is being confirmed.
audit_idstringIdentifier of the request's usage record. Quote it with request_id when you contact support.
audio_persistedbooleantrue when the audio was saved to your workspace history in Studio.

error

The final event of a failed request. It replaces finish, and audio already sent may have played.

json
{
  "event": "error",
  "request_id": "rq_0f8c2d4e-...",
  "code": "provider_unavailable",
  "retryable": true,
  "detail": "The requested voice is temporarily unavailable."
}

See Errors for codes, retry guidance and close codes.

Contact our team

Tell us about your character and what you’d like to build.