Skip to main content
For a model whose page lists streaming, set stream: true on POST /v1/chat/completions to get a Server-Sent Events response. Add stream_options.include_usage when your client needs the usage frame. /v1/messages uses a different, event-named stream grammar described in Anthropic Messages.

What arrives, and when

Streaming timeline”stream”: truerequestHTTP 200, event stream opensfirst tokenwithin the 180s TTFT budgetdelta framesone complete frame at a timeusage frameopt-in, or no final answer740s response budget, then 504How a stream endsdata: [DONE]the normal terminal frame after the last deltaerror framea stream that fails mid-generation ends with one final frame carrying the standardupstream_stream_errorenvelope, on the same HTTP 200. Handle it in your frame loop.Only tokens actually delivered to you are billed.
Streaming timeline”stream”: truerequestHTTP 200, event stream opensfirst tokenwithin the 180s TTFT budgetdelta framesone complete frame at a timeusage frameopt-in, or no final answer740s response budget, then 504How a stream endsdata: [DONE]the normal terminal frame after the last deltaerror framea stream that fails mid-generation ends with one final frame carrying the standardupstream_stream_errorenvelope, on the same HTTP 200. Handle it in your frame loop.Only tokens actually delivered to you are billed.

Frame shapes

The response carries Content-Type: text/event-stream, Cache-Control: no-cache and Connection: keep-alive. Content arrives in OpenAI-compatible data: frames, and partial output is on choices[].delta.
The usage frame has an empty choices array. On a hosted model it also carries the request’s cost and the count of input tokens billed at the cached rate, both described in Chat completions:
A completed stream ends with data: [DONE]. A stream the gateway terminates early ends with an error frame and no [DONE], so treat a missing [DONE] as an incomplete response (see Errors).

Is usage always included?

No. The gateway always asks the model for usage so it can settle the request, but it forwards the usage frame to you only when your request carried stream_options.include_usage: true. Omit it and content frames still stream while usage-only frames stay hidden. A usage frame is never synthesized: if the model reports no usage for a request, none is sent. There is one exception, so you can account for generated tokens even when no answer was delivered. When every choice finishes without final answer content, the gateway forwards one annotated usage frame whether or not you opted in.

When a stream ends without an answer

A choice that reaches its generation limit before producing answer content carries a machine-readable status on its terminal frame:
If another terminal finish_reason produced no answer, the code is no_answer_content instead. Inspect the preserved finish_reason before deciding whether to retry. The annotated usage frame then reports how much of the generated output was not an answer:
A stream that produced no answer settles at zero, so this frame says cost: 0 and cached_tokens: 0 whatever the model reported: nothing was priced, at either rate. The usual cause is an output budget too small for a model that reasons first. See give reasoning models room.
An Idempotency-Key on a streaming request stops a retry from generating and charging twice, but delivered tokens are never stored and never replayed. Read Idempotent retries before retrying a stream.

Chat completions

The request contract every stream starts from.

Idempotent retries

Retry a dropped stream without paying twice.

Errors

Every status, code, and caller action.