v1

latestOpenAPI 3.1.02026-07-224941145.6 KB

Image Generation (Streaming)

Generate images using Gemini 2.5 Flash Image in streaming mode via SSE. The endpoint returns newline-delimited Server-Sent Events. Thinking chunks (thought=true) arrive first, followed by the image chunk containing inlineData, and finally a usage metadata chunk.

post/v1beta/models/gemini-2.5-flash-image:streamGenerateContent

Query parameters

keystring required

API Key

alt'sse'

Set to sse for explicit Server-Sent Events mode (optional, streaming is the default behaviour of this endpoint)

Request body

Example request

{
  "contents": [
    {
      "role": "user",
      "parts": [
        {
          "text": "Generate an image of a sunset over mountains"
        }
      ]
    }
  ],
  "generationConfig": {
    "responseModalities": [
      "TEXT",
      "IMAGE"
    ],
    "imageConfig": {
      "aspectRatio": "16:9",
      "imageSize": "1K"
    }
  }
}

Response

Streaming SSE response. Each line starts with "data:" followed by a JSON chunk. Three chunk types are delivered in order: (1) Thinking chunks — parts[0].thought is true; (2) Image chunk — parts[0].inlineData contains mimeType and base64 data (camelCase); (3) Final usage chunk — top-level usageMetadata with thoughtsTokenCount.

modelVersionstring
createTimestring
responseIdstring

Example response

{
  "candidates": [
    {
      "content": {
        "role": "model",
        "parts": [
          {
            "thought": true,
            "inlineData": {
              "mimeType": "image/png",
              "data": "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+M9QDwADhgGAWjR9awAAAABJRU5ErkJggg=="
            }
          }
        ]
      }
    }
  ],
  "usageMetadata": {
    "promptTokenCount": 8,
    "candidatesTokenCount": 1120,
    "totalTokenCount": 1392,
    "thoughtsTokenCount": 264,
    "trafficType": "ON_DEMAND",
    "promptTokensDetails": [
      {
        "modality": "TEXT",
        "tokenCount": 8
      }
    ],
    "candidatesTokensDetails": [
      {
        "modality": "IMAGE",
        "tokenCount": 1120
      }
    ]
  },
  "modelVersion": "gemini-3.1-flash-lite-image",
  "createTime": "2025-01-01T00:00:00Z",
  "responseId": "abc123"
}