> ## Documentation Index
> Fetch the complete documentation index at: https://docs.anyfast.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# gemini-3.1-flash-image-stream

> Generate images using Gemini 3.1 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.




## OpenAPI

````yaml api-reference/model-api/google/openapi/gemini-3.1-flash-image-stream/openapi.yaml POST /v1beta/models/gemini-3.1-flash-image:streamGenerateContent
openapi: 3.1.0
info:
  title: Gemini 3.1 Flash Image (Stream)
  description: Google Gemini 3.1 Flash Image streaming image generation via Anyfast proxy
  version: 1.0.0
servers:
  - url: https://www.anyfast.ai
security: []
paths:
  /v1beta/models/gemini-3.1-flash-image:streamGenerateContent:
    post:
      summary: Image Generation (Streaming)
      description: >
        Generate images using Gemini 3.1 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.
      operationId: Gemini31FlashImageStreamGenerateContent
      parameters:
        - name: key
          in: query
          description: API Key
          required: true
          schema:
            type: string
          example: YOUR_API_KEY
        - name: alt
          in: query
          description: >-
            Set to sse for explicit Server-Sent Events mode (optional, streaming
            is the default behaviour of this endpoint)
          required: false
          schema:
            type: string
            enum:
              - sse
          example: sse
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
                - contents
                - generationConfig
              properties:
                contents:
                  type: array
                  description: >
                    Array of conversation turns. Each turn has a role and parts.
                    A part can be a text prompt, or an inline_data image
                    (base64). To use a reference image, include both a text part
                    and an inline_data part in the same parts array.
                  items:
                    type: object
                    properties:
                      role:
                        type: string
                        enum:
                          - user
                          - model
                        example: user
                      parts:
                        type: array
                        description: >
                          List of content parts. Combine text and inline_data in
                          the same array to send a prompt alongside a reference
                          image.
                        items:
                          type: object
                          properties:
                            text:
                              type: string
                              description: Text prompt
                              example: Generate an image of a sunset over mountains
                            inline_data:
                              type: object
                              description: >
                                Reference image encoded as base64 (snake_case in
                                request body). Note: in the streaming response,
                                the field is inlineData (camelCase).
                              properties:
                                mime_type:
                                  type: string
                                  description: >-
                                    MIME type of the image. Supported:
                                    image/jpeg, image/png, image/webp
                                  enum:
                                    - image/jpeg
                                    - image/png
                                    - image/webp
                                  example: image/jpeg
                                data:
                                  type: string
                                  description: Base64-encoded image data.
                                  example: >-
                                    iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+M9QDwADhgGAWjR9awAAAABJRU5ErkJggg==
                  example:
                    - role: user
                      parts:
                        - text: Generate an image of a sunset over mountains
                generationConfig:
                  type: object
                  required:
                    - responseModalities
                  properties:
                    responseModalities:
                      type: array
                      description: >
                        Output modalities. Use ["IMAGE"] for image-only output,
                        or ["TEXT", "IMAGE"] to receive both a caption and the
                        image.
                      items:
                        type: string
                        enum:
                          - TEXT
                          - IMAGE
                      example:
                        - TEXT
                        - IMAGE
                    imageConfig:
                      type: object
                      description: Image generation configuration
                      properties:
                        aspectRatio:
                          type: string
                          description: Desired aspect ratio of the generated image.
                          enum:
                            - '1:1'
                            - '4:3'
                            - '3:4'
                            - '16:9'
                            - '9:16'
                          example: '16:9'
                        imageSize:
                          type: string
                          description: >
                            Resolution of the generated image. 1K ≈ 1024px, 2K ≈
                            2048px, 4K ≈ 4096px on the long edge.
                          enum:
                            - 1K
                            - 2K
                            - 4K
                          example: 1K
      responses:
        '200':
          description: >
            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.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/StreamChunk'
              example:
                candidates:
                  - content:
                      role: model
                      parts:
                        - inlineData:
                            mimeType: image/png
                            data: >-
                              iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+M9QDwADhgGAWjR9awAAAABJRU5ErkJggg==
                usageMetadata:
                  trafficType: ON_DEMAND
                modelVersion: gemini-3.1-flash-image
        '400':
          description: Invalid request
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '401':
          description: Unauthorized
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '429':
          description: Rate limit exceeded
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
components:
  schemas:
    StreamChunk:
      type: object
      description: >
        A single SSE chunk. Three variants are possible: thinking chunk
        (parts[].thought=true), image chunk (parts[].inlineData), or usage chunk
        (no candidates).
      properties:
        candidates:
          type: array
          description: >-
            Present in thinking and image chunks; absent in the final usage
            chunk.
          items:
            type: object
            properties:
              content:
                type: object
                properties:
                  role:
                    type: string
                    example: model
                  parts:
                    type: array
                    items:
                      type: object
                      properties:
                        text:
                          type: string
                          description: Thinking text (present in thinking chunks)
                        thought:
                          type: boolean
                          description: True when this part is an internal thinking chunk
                          example: true
                        inlineData:
                          type: object
                          description: >
                            Generated image data (camelCase; present in image
                            chunk only). Note: the request body uses inline_data
                            (snake_case).
                          properties:
                            mimeType:
                              type: string
                              example: image/png
                            data:
                              type: string
                              description: Base64-encoded generated image
                              example: >-
                                iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+M9QDwADhgGAWjR9awAAAABJRU5ErkJggg==
        usageMetadata:
          type: object
          description: >-
            Token usage. Final chunk contains full details including
            thoughtsTokenCount.
          properties:
            promptTokenCount:
              type: integer
              example: 8
            candidatesTokenCount:
              type: integer
              example: 1120
            totalTokenCount:
              type: integer
              example: 1392
            thoughtsTokenCount:
              type: integer
              description: >-
                Number of tokens used for internal thinking (present in final
                usage chunk)
              example: 264
            trafficType:
              type: string
              example: ON_DEMAND
            promptTokensDetails:
              type: array
              items:
                type: object
                properties:
                  modality:
                    type: string
                    example: TEXT
                  tokenCount:
                    type: integer
                    example: 8
            candidatesTokensDetails:
              type: array
              items:
                type: object
                properties:
                  modality:
                    type: string
                    example: IMAGE
                  tokenCount:
                    type: integer
                    example: 1120
        modelVersion:
          type: string
          example: gemini-3.1-flash-image
        createTime:
          type: string
          example: '2025-01-01T00:00:00Z'
        responseId:
          type: string
          example: abc123
    Error:
      type: object
      properties:
        error:
          type: object
          properties:
            code:
              type: integer
            message:
              type: string
            status:
              type: string

````