Add "stream": true to the body to receive the response incrementally over Server-Sent Events (SSE). Works with /v1/chat/completions, /v1/responses and /v1/messages. The /v1/responses stream uses the standard Responses events (response.created … response.completed), and a mid-stream error is a response.failed event.
How it works
- The
200headers are sent right away (content-type: text/event-stream), before the model starts answering. - Data chunks keep the SSE format of the API you call (OpenAI or Anthropic), so SDKs read the stream as usual.
- OpenAI format: the stream always ends with a chunk that contains
usage(tokens used). - If the model has not sent anything for 15 seconds, a
: pingcomment line is sent so the connection is not dropped. Standard SSE parsers ignore it.
Mid-stream errors
If an error happens after the 200 headers have been sent, it arrives as an event in the stream.
Anthropic format:
Text
event: error
data: {"type":"error","error":{"type":"overloaded_error","message":"…"}}OpenAI format:
Text
data: {"error":{"message":"…","type":"server_error","code":"service_unavailable","param":null}}Billing
- If you disconnect after receiving part of the response, the request stops. You are charged for the tokens used up to that point (input plus the output generated so far), subject to the minimum charge per request.
- If you cancel after the request has been sent to the model but before any content arrives, you are charged for the input tokens (including any reported cache tokens) or the minimum charge per request, whichever is higher. Output tokens are not charged.
- A request (streaming or not) runs for at most 15 minutes.