Skip to content
Rapid Router
Guides · Build

Streaming

Server-sent events in the standard chunk shape, with the billed cost in a closing usage chunk when you ask for it.

Set "stream": true for server-sent events. Deltas arrive in the standard chunk shape and the stream terminates with data: [DONE]. To get the billed cost on the stream, set "stream_options": { "include_usage": true }, as with OpenAI: a final chunk with empty choices then carries usage and its cost. Without it no such chunk is sent, so a loop that reads chunk.choices[0] never meets an empty one. The bill is the same either way.

sse, with include_usage
data: {"object":"chat.completion.chunk","model":"anthropic/claude-sonnet-5","choices":[{"index":0,"delta":{"content":"Rou"},"finish_reason":null}]}
data: {"object":"chat.completion.chunk","model":"anthropic/claude-sonnet-5","choices":[{"index":0,"delta":{"content":"ting"},"finish_reason":null}]}
data: {"object":"chat.completion.chunk","model":"anthropic/claude-sonnet-5","choices":[{"index":0,"delta":{},"finish_reason":"stop"}]}
data: {"object":"chat.completion.chunk","choices":[],"usage":{"prompt_tokens":18,"completion_tokens":96,"total_tokens":114,"cost":0.00074}}
data: [DONE]