Streaming
To stream a response, set "stream": true. The router sends it as a Server-Sent Events (SSE) stream: tokens arrive as they are generated instead of in one block at the end. The stream format matches the endpoint. The /v1/responses stream is covered in Responses API.
Chat Completions
Section titled “Chat Completions”POST /v1/chat/completions returns an OpenAI-compatible stream. Each event is a data: line with a chat.completion.chunk object, and the text is in choices[].delta.content. The stream ends with a data: [DONE] line.
curl https://api.waibee.com/v1/chat/completions \ -H "Authorization: Bearer $WAIBEE_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "model": "anthropic/claude-sonnet-4.6", "stream": true, "messages": [{ "role": "user", "content": "Hello!" }] }'data: {"object":"chat.completion.chunk","choices":[{"index":0,"delta":{"role":"assistant","content":"Hello! How"}}]}
data: {"object":"chat.completion.chunk","choices":[{"index":0,"delta":{"content":" are"}}]}
data: [DONE]Messages
Section titled “Messages”POST /v1/messages returns a stream of Anthropic-format events. Each event is a pair of event: and data: lines. The events come in this order: message_start, then content_block_start, a series of content_block_delta events with text, content_block_stop, message_delta, and message_stop. If the response has several blocks (reasoning, text, a tool call), the three content_block_* events repeat for each one. This format has no data: [DONE] line: the stream ends after message_stop.
curl https://api.waibee.com/v1/messages \ -H "x-api-key: $WAIBEE_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "model": "anthropic/claude-sonnet-4.6", "stream": true, "max_tokens": 1024, "messages": [{ "role": "user", "content": "Hello!" }] }'event: message_startdata: {"type":"message_start","message":{"role":"assistant","content":[]}}
event: content_block_deltadata: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"Hello! How"}}
event: message_stopdata: {"type":"message_stop"}Errors mid-stream
Section titled “Errors mid-stream”An error before the stream starts (API key, balance, validation, DLP, the model rejecting the request) comes as an ordinary HTTP response with a code from Errors.
Once the stream has started, the HTTP status stays 200, and the error arrives as an error event:
/v1/chat/completions:event: error, with a chunk indatathat has anerrorfield (codeandmessage) andfinish_reason: "error", followed bydata: [DONE];/v1/messages:event: errorwith the body{"type": "error", "error": {"type": ..., "code": ..., "message": ...}}. Useerror.codeto find the cause: oneerror.typecovers several codes;/v1/responses: see Responses API.
What to keep in mind
Section titled “What to keep in mind”- The stream can contain SSE comment lines (they start with
:). These are keep-alives: the router sends them while the model is silent, for example while it reasons. Ignore them. - Which events carry token counters depends on the stream format; see Tokens and usage.
- The official SDKs (
openai,anthropic) parse the stream for you: turn on streaming in the call (stream=True), and the text arrives in parts. See Integrations.