stream: true on a chat completions request to receive the response as server-sent events.
Event format
- The response has the content type
text/event-stream. - Each event’s
datais a JSON object withobject: "chat.completion.chunk". The new text is inchoices[].delta.content. - Reasoning arrives in
delta.reasoninganddelta.reasoning_details. Tool call arguments arrive indelta.tool_calls. - The stream ends with the line
data: [DONE].
Usage on the final chunk
boolean
true adds a final chunk with usage, sent before data: [DONE]. Without it, the stream has no usage data. Billing is the same either way.Read a stream
Keep-alives and timeouts
- While no data is ready, the stream sends a keep-alive comment at least every 30 seconds. A comment is a line that starts with
:. Skip these lines in a custom parser. - Set the client read timeout above 30 seconds. A shorter timeout can close a stream that is still working.
- A request can run for up to 60 minutes — see Rate limits. A stream that reaches the limit ends with the error event below.
Errors during a stream
If the request fails before the first event, the response is an ordinary error with an HTTP status and a JSON body — see Errors. If it fails after the stream started, the last event is an error, and the stream closes. Every failure at this point, a timeout included, has the codeupstream_error:
data: [DONE] and without an error event lost its connection. A stopped stream cannot be resumed; a new request is charged separately — see What is billed. The x-request-id response header identifies the request for support.