AGTCloud API Docs
GuidesAPI ReferenceIntegrations and resourcesUpdate and help
Text and chat

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.

POST/v1beta/models/{model}:streamGenerateContent

Use SSE to continuously return the GenerateContentResponse data block.

Authorization

bearerAuth
AuthorizationBearer <token>

Use Bearer your-api-key in the Authorization Header.

In: header

Path Parameters

model*string

Model ID used to generate content. The path automatically forms models/{model}.

Default"MODEL_ID"

Query Parameters

alt*"sse"

Select the SSE transfer format. This parameter is a URL query parameter and not part of the GenerateContentRequest body.

Default"sse"

Value in

  • "sse"

Request Body

Gemini uses Content and Parts to represent text, multimodal input, tools, and generation settings.

application/json
Text chat

Use 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.
application/json
{
  "contents": [
    {
      "role": "user",
      "parts": [
        {
          "text": "Hello! Please introduce yourself."
        }
      ]
    }
  ]
}
Field referenceThe complete field set is unchanged; descriptions emphasize the current use case.

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.

Google Gemini Stream Generate Content documentationReview the upstream streaming protocol definition and the latest field changes.