Skip to main content
POST
Image generation (streaming)

Query Parameters

key
string
required

API key

alt
enum<string>

Set to sse to explicitly enable SSE mode (optional; streaming is the default behavior of this endpoint)

Available options:
sse

Body

application/json
contents
object[]
required

Array of conversation turns. Each turn includes role and parts. A part can be a text prompt or inline_data Image (base64). To pass a reference image, include both a text part and inline_data part。

Example:
generationConfig
object
required

Response

Streaming SSE response. Each line starts with "data:" followed by a JSON chunk. Three chunk types are sent in order: (1) thinking chunk — parts[0].thought is true; (2) image chunk — parts[0].inlineData contains mimeType and base64 data (camelCase); (3) final usage chunk — top-level usageMetadata, including thoughtsTokenCount。

A single SSE chunk. There are three types: thinking chunks (parts[].thought=true), image chunks (parts[].inlineData), and usage chunks (no candidates).

candidates
object[]

Present in thinking chunks and image chunks; omitted from the final usage chunk.

usageMetadata
object

Token usage. The final chunk includes full details, including thoughtsTokenCount.

modelVersion
string
Example:

"gemini-3.1-flash-image-preview"

createTime
string
Example:

"2025-01-01T00:00:00Z"

responseId
string
Example:

"abc123"