Gemini Stream Generate Content
Receive streaming generation results over SSE with the Gemini Stream Generate Content endpoint.
Stream Generate Content uses the same Content, Parts, Bearer authentication, and generation configuration as standard generation, then continuously returns GenerateContentResponse chunks over one-way SSE. It is different from the bidirectional WebSocket-based Live API.
Clients should parse each SSE data: field at blank-line boundaries, then assemble text or Structured Output fragments in order. Do not call JSON.parse once on the entire response stream. Intermediate chunks might not contain finishReason; keep the latest usageMetadata when it appears. The same responseId associates every chunk in one generation. If candidates is missing, inspect promptFeedback.
/v1beta/models/{model}:streamGenerateContentUse SSE to continuously return the GenerateContentResponse data block.
Authorization
bearerAuth Use Bearer your-api-key in the Authorization Header.
In: header
Path Parameters
Model ID used to generate content. The path automatically forms models/{model}.
"MODEL_ID"Query Parameters
Select the SSE transfer format. This parameter is a URL query parameter and not part of the GenerateContentRequest body.
"sse"Value in
- "sse"
Request Body
Gemini uses Content and Parts to represent text, multimodal input, tools, and generation settings.
application/jsonUse user and model Content objects to organize single-turn or multi-turn text conversations.
- contents[]
- Conversation content in chronological order.
- parts[].text
- Text content in each message.
- role
- Message author; commonly user or model.
{
"contents": [
{
"role": "user",
"parts": [
{
"text": "Hello! Please introduce yourself."
}
]
}
]
}Use Content objects and text Parts to organize single-turn or multi-turn text conversations.
Response Body
text/event-stream
application/json
application/json
application/json
application/json
application/json
application/json
application/json
application/json
application/json
SSE data structure
These fields describe the JSON in one data: event, not the complete SSE text stream.