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:
| Credential | How to send it | Use from |
|---|---|---|
| API key | Authorization: Bearer awp_... header | Your server |
| Stream token | ?token=... query parameter, or the Authorization header | Browsers 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
| Direction | Event | When |
|---|---|---|
| Client → server | start | Exactly once, first. |
| Client → server | text | One or more times. |
| Client → server | flush | Optional, between text events. |
| Client → server | stop | Exactly once, last. |
| Server → client | audio | Zero or more times, in order. |
| Server → client | usage | Once, after the last audio event. |
| Server → client | finish | Once, last, on success. |
| Server → client | error | Once, 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.
{
"event": "start",
"request": {
"voice_id": "YOUR_VOICE_ID",
"output_format": "pcm_48000",
"context_id": "assistant_turn_7"
}
}| Field | Type | Required | Description |
|---|---|---|---|
request.voice_id | string | Yes | A voice ID from GET /v1/voices. |
request.output_format | string | Yes | One of pcm_24000, pcm_44100, pcm_48000, aac_44100_128. Must be supported by the model. |
request.model | string | No | A model ID from GET /v1/models. Defaults to Waffle Mono. |
request.realtime | boolean | No | Use the realtime tier. Defaults to false. |
request.context_id | string | No | Your identifier for this utterance, up to 200 characters. Echoed on audio events. |
request.partner_session_id | string | No | Your 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.
{ "event": "text", "text": "Your order is ready, " }| Field | Type | Required | Description |
|---|---|---|---|
text | string | Yes | 1–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.
{ "event": "flush" }stop
Generates any remaining text and ends the request. No more client events are accepted.
{ "event": "stop" }audio
A chunk of generated audio.
{
"event": "audio",
"request_id": "rq_0f8c2d4e-...",
"context_id": "assistant_turn_7",
"seq": 1,
"format": "pcm_48000",
"audio": "AAABAAIA..."
}| Field | Type | Description |
|---|---|---|
request_id | string | The request's ID. |
context_id | string | Your context_id, when you sent one. |
seq | integer | Chunk number, starting at 1 and increasing across flushes. |
format | string | The delivered format. Use it to choose the decoder. |
channels | integer | 2 for stereo. Absent for mono. |
audio | string | Base64-encoded audio bytes. |
usage
Totals for the request, sent once after the last chunk.
{
"event": "usage",
"request_id": "rq_0f8c2d4e-...",
"voice_id": "YOUR_VOICE_ID",
"usage": { "chars": 48, "audio_ms": 2760 }
}| Field | Type | Description |
|---|---|---|
usage.chars | integer | Characters generated. |
usage.audio_ms | integer | Length of the generated audio in milliseconds. |
voice_id | string | The voice used. |
finish
The final event of a successful request. The server closes the connection with code 1000 afterwards.
{
"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
}| Field | Type | Description |
|---|---|---|
reason | string | stop when the request completed normally. |
cost.credits | number | Credits charged for the request. |
cost.amount | number | The credits' value in cost.currency. |
cost.settlement_status | string | settled, or pending while the final charge is being confirmed. |
audit_id | string | Identifier of the request's usage record. Quote it with request_id when you contact support. |
audio_persisted | boolean | true 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.
{
"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.