Streaming
Streaming
Set "stream": true in the request body to receive output as Server-Sent Events while it is being generated — ideal for chat UIs.
Chat Completions
Each event is a data: {...} line where choices[0].delta.content carries the new text; the stream ends with data: [DONE].
To receive usage in a streamed response, pass:
The final chunk then includes a usage object.
Python SDK
Other protocols
Anthropic Messages (/v1/messages): pass "stream": true to receive message_start, content_block_delta, message_stop and related events. Responses (/v1/responses): pass "stream": true to receive response.output_text.delta and related events. Native Gemini API: use :streamGenerateContent?alt=sse.
Always stream long-running requests (long outputs, reasoning models, coding agents) so intermediate proxies don't drop an idle connection.