streamGenerateContent
Google Gemini
streamGenerateContent
POST /v1beta/models/:streamGenerateContent — Gemini streaming generation
POST
streamGenerateContent
Identical to generateContent, but returned as a stream — chunks are pushed as they’re generated, reducing time-to-first-token.
Note the query parameter
The last chunk usually carries
Request
?alt=sse — without it, the response is a JSON array (one complete candidate per item);
only with alt=sse do you get a standard SSE stream (the data: {...} form).
Stream chunks
finishReason and usageMetadata.
Python (google-genai)
Notes
- Streaming responses also support
tools/ function calling / thinking mode — those fields appear within some chunk. - The client must handle retries after an SSE disconnect (it is not idempotent — a retry is billed again).