data:. The SDKs handle the framing.
Turn It On
Setstream: true on the same chat request:
-N turns off curl’s buffering so tokens show as they arrive.
The Stream
- New text is in
choices[0].delta.content. Concatenate the chunks to rebuild the reply. delta.role: "assistant"appears once, on the first chunk that carries content or reasoning.- The last content chunk sets
finish_reason:stop,length,tool_calls, orerror. data: [DONE]ends the stream. It is not JSON.: keep-alivecomment lines can appear. Ignore them.
Usage
Usage is known only when generation finishes. Ask for it:choices array and a usage object arrives before data: [DONE].
Mid-Stream Errors
Once the stream starts, HTTP200 is already sent. A later failure arrives as a final chunk with a top-level error object, an empty delta, and finish_reason: "error", and the stream ends without data: [DONE]. Check each chunk for error as well as the status. A failure before any byte is written returns an ordinary HTTP error.
Related
Stream Format Reference
Every chunk field.
Make Your First Request
Non-streaming.
Tool Call Streaming
Tool calls in fragments.

