Streaming & cancellation
Read incremental events and distinguish completion from a broken stream.
SSE framing
Set stream=true. Read UTF-8 incrementally, buffer complete blank-line-separated events and parse the data field. Network chunks do not align with JSON objects, Unicode characters or event boundaries.
data: {"choices":[{"delta":{"content":"Hello"}}]}
data: {"choices":[{"delta":{"content":"!"}}]}
data: [DONE]
Completion
A chat stream completes only after [DONE]. An EOF, timeout or error event before that marker is incomplete. Never display an interrupted reply as a successful generation. Cancel readers and network requests when navigating away or pressing Stop.