Set stream: true to receive Server-Sent Events as chat.completion.chunk frames:
- The first frame carries
delta.role: "assistant" and the top-level citations[] extension.
- Subsequent frames carry
delta.content text deltas.
- The terminal frame carries
finish_reason.
- The stream ends with
data: [DONE].
Once stream: true is set, every error — including authentication and validation failures — is emitted as a single terminal frame, data: {"error":{...}}, under HTTP 200, with no trailing data: [DONE]. Do not branch on the HTTP status for streaming requests.The error frame carries no choices, so a hand-rolled parser doing chunk["choices"][0] gets a KeyError. A genuine mid-stream error is always api_error, and any text already emitted stays on the reader’s screen with no truncation marker.