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

# Gemini Generate Image

> Use DeerAPI to call the Gemini Generate Image endpoint with request details, response details, examples, and an OpenAPI playground.

## Overview

Use this endpoint to call the Gemini Generate Image workflow through DeerAPI. The API reference on this page shows the request schema, response schema, authentication requirements, and runnable examples for the configured endpoint.

## Before you start

Use the DeerAPI base URL and pass your API Key in the `Authorization` header:

```text theme={null}
https://api.deerapi.com
```

```text theme={null}
Authorization: Bearer $DEERAPI_KEY
```

## Model selection

Choose a current model ID from the [live pricing page](https://api.deerapi.com/pricing). Model availability changes over time, so avoid copying a model ID from an old project without checking the live list first.

## Implementation notes

* Use the OpenAPI playground for the exact request fields accepted by this endpoint.
* Keep API Keys on the server side when you build production applications.
* Log the request ID from failed calls so support can investigate the request.
* Retry `429`, `500`, and `503` responses with exponential backoff.


## OpenAPI

````yaml /api/openapi/image/gemini/post-gemini-image.openapi.json POST /v1beta/models/{model}:generateContent
openapi: 3.1.0
info:
  title: Gemini Image Generation API
  version: 1.0.0
servers:
  - url: https://api.deerapi.com
security:
  - bearerAuth: []
paths:
  /v1beta/models/{model}:generateContent:
    post:
      summary: Gemini Image Generation
      operationId: gemini_generates_image
      parameters:
        - name: model
          in: path
          required: true
          description: >-
            The Gemini image model to use. See the [Models
            page](https://api.deerapi.com/pricing) for current options.
          schema:
            type: string
            default: gemini-3.1-flash-image-preview
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
                - contents
              properties:
                contents:
                  type: array
                  description: >-
                    Conversation turns. Each item has a `role` ("user" or
                    "model") and `parts` array containing text and/or image
                    data.
                  items:
                    type: object
                    properties:
                      role:
                        type: string
                        description: Role of the message sender.
                        enum:
                          - user
                          - model
                      parts:
                        type: array
                        description: >-
                          Content blocks — text prompts and/or inline image
                          data.
                        items:
                          type: object
                          properties:
                            text:
                              type: string
                              description: Text content (prompt or instruction).
                            inline_data:
                              type: object
                              description: >-
                                Inline image data for image-to-image or
                                multi-image input.
                              properties:
                                mime_type:
                                  type: string
                                  description: MIME type of the image.
                                  enum:
                                    - image/jpeg
                                    - image/png
                                    - image/webp
                                data:
                                  type: string
                                  description: >-
                                    Raw Base64-encoded image data. Do not
                                    include the `data:image/...;base64,` prefix.
                generationConfig:
                  type: object
                  description: >-
                    Controls generation behavior — output modalities, image
                    resolution, thinking, etc.
                  properties:
                    responseModalities:
                      type: array
                      description: >-
                        Output types to return. Use `["TEXT", "IMAGE"]` for
                        mixed output, or `["IMAGE"]` to force image-only output.
                      items:
                        type: string
                        enum:
                          - TEXT
                          - IMAGE
                      default:
                        - TEXT
                        - IMAGE
                    imageConfig:
                      type: object
                      description: Image output configuration.
                      properties:
                        aspectRatio:
                          type: string
                          description: >-
                            All models: `1:1` `2:3` `3:2` `3:4` `4:3` `4:5`
                            `5:4` `9:16` `16:9` `21:9`. Gemini 3.1 Flash also
                            supports `1:4` `4:1` `1:8` `8:1`.
                          default: '1:1'
                        imageSize:
                          type: string
                          description: >-
                            Output resolution. Gemini 3 models only —
                            `gemini-2.5-flash-image` always outputs 1024px. Use
                            uppercase K.
                          enum:
                            - 512px
                            - 1K
                            - 2K
                            - 4K
                          default: 1K
                    thinkingConfig:
                      type: object
                      description: >-
                        Controls the Thinking process (Gemini 3 models).
                        Thinking generates interim images before the final
                        output.
                      properties:
                        thinkingLevel:
                          type: string
                          description: >-
                            Thinking effort level. Only configurable for
                            `gemini-3.1-flash-image-preview`;
                            `gemini-3-pro-image-preview` always uses high
                            thinking.
                          enum:
                            - minimal
                            - high
                          default: minimal
                        includeThoughts:
                          type: boolean
                          description: Whether to include thought parts in the response.
                          default: false
                tools:
                  type: array
                  description: >-
                    Optional tools. Pass `[{"google_search": {}}]` to enable
                    Google Search grounding for real-time information in
                    generated images.
                  items:
                    type: object
                    properties:
                      google_search:
                        type: object
                        description: Enables Google Search grounding.
            examples:
              text-to-image:
                summary: Text to Image
                value:
                  contents:
                    - role: user
                      parts:
                        - text: >-
                            A Monarch butterfly anatomical sketch on textured
                            parchment, Da Vinci style
                  generationConfig:
                    responseModalities:
                      - TEXT
                      - IMAGE
                    imageConfig:
                      aspectRatio: '1:1'
                      imageSize: 4K
              image-to-image:
                summary: Image to Image
                value:
                  contents:
                    - role: user
                      parts:
                        - text: Transform this into a watercolor painting
                        - inline_data:
                            mime_type: image/jpeg
                            data: <base64-encoded-image>
                  generationConfig:
                    responseModalities:
                      - TEXT
                      - IMAGE
              multi-image-composition:
                summary: Multi-Image Composition
                value:
                  contents:
                    - role: user
                      parts:
                        - text: Blend these images into one scene
                        - inline_data:
                            mime_type: image/jpeg
                            data: <base64-image-1>
                        - inline_data:
                            mime_type: image/jpeg
                            data: <base64-image-2>
                  generationConfig:
                    responseModalities:
                      - TEXT
                      - IMAGE
              force-image-only:
                summary: Force Image Output
                value:
                  contents:
                    - role: user
                      parts:
                        - text: A photo-realistic sunset over the ocean
                  generationConfig:
                    responseModalities:
                      - IMAGE
                    imageConfig:
                      aspectRatio: '16:9'
                      imageSize: 2K
              with-thinking:
                summary: With Thinking (3.1 Flash)
                value:
                  contents:
                    - role: user
                      parts:
                        - text: >-
                            A futuristic city inside a glass bottle floating in
                            space
                  generationConfig:
                    responseModalities:
                      - IMAGE
                    thinkingConfig:
                      thinkingLevel: high
                      includeThoughts: true
              with-search-grounding:
                summary: With Google Search Grounding
                value:
                  contents:
                    - role: user
                      parts:
                        - text: >-
                            Visualize the current weather forecast for San
                            Francisco as a chart
                  generationConfig:
                    responseModalities:
                      - TEXT
                      - IMAGE
                  tools:
                    - google_search: {}
            example:
              contents:
                - role: user
                  parts:
                    - text: >-
                        A Monarch butterfly anatomical sketch on textured
                        parchment, Da Vinci style
              generationConfig:
                responseModalities:
                  - TEXT
                  - IMAGE
                imageConfig:
                  aspectRatio: '1:1'
                  imageSize: 4K
      responses:
        '200':
          description: Success
          content:
            application/json:
              schema:
                type: object
                properties:
                  candidates:
                    type: array
                    items:
                      type: object
                      properties:
                        content:
                          type: object
                          properties:
                            role:
                              type: string
                              description: Always `model` for responses.
                            parts:
                              type: array
                              description: >-
                                Response parts — may contain text, images, or
                                both.
                              items:
                                type: object
                                properties:
                                  text:
                                    type: string
                                    description: Text content from the model.
                                  inlineData:
                                    type: object
                                    description: Generated image data.
                                    properties:
                                      mimeType:
                                        type: string
                                        description: Image MIME type, typically `image/png`.
                                      data:
                                        type: string
                                        description: Base64-encoded image data.
                        finishReason:
                          type: string
                          description: Reason generation stopped.
                          enum:
                            - STOP
                            - MAX_TOKENS
                            - SAFETY
                            - RECITATION
                        index:
                          type: integer
                        safetyRatings:
                          type: array
                          items:
                            type: object
                            properties:
                              category:
                                type: string
                              probability:
                                type: string
                  usageMetadata:
                    type: object
                    properties:
                      promptTokenCount:
                        type: integer
                      candidatesTokenCount:
                        type: integer
                      totalTokenCount:
                        type: integer
                      thoughtsTokenCount:
                        type: integer
                        description: >-
                          Token count for thinking process (Gemini 3 models
                          only).
      x-codeSamples:
        - lang: Shell
          label: cURL
          source: >
            curl
            https://api.deerapi.com/v1beta/models/gemini-3.1-flash-image-preview:generateContent
            \
              -H "Content-Type: application/json" \
              -H "Authorization: Bearer $DEERAPI_KEY" \
              -d '{
                "contents": [
                  {
                    "role": "user",
                    "parts": [
                      {
                        "text": "A Monarch butterfly anatomical sketch on textured parchment, Da Vinci style"
                      }
                    ]
                  }
                ],
                "generationConfig": {
                  "responseModalities": [
                    "TEXT",
                    "IMAGE"
                  ],
                  "imageConfig": {
                    "aspectRatio": "1:1",
                    "imageSize": "4K"
                  }
                }
              }'
        - lang: Python
          label: requests
          source: >
            import os

            import requests


            url =
            "https://api.deerapi.com/v1beta/models/gemini-3.1-flash-image-preview:generateContent"

            headers = {
                "Authorization": "Bearer " + os.environ["DEERAPI_KEY"],
                "Content-Type": "application/json",
            }

            payload = {
              "contents": [
                {
                  "role": "user",
                  "parts": [
                    {
                      "text": "A Monarch butterfly anatomical sketch on textured parchment, Da Vinci style"
                    }
                  ]
                }
              ],
              "generationConfig": {
                "responseModalities": [
                  "TEXT",
                  "IMAGE"
                ],
                "imageConfig": {
                  "aspectRatio": "1:1",
                  "imageSize": "4K"
                }
              }
            }


            response = requests.post(url, headers=headers, json=payload)

            print(response.json())
        - lang: JavaScript
          label: fetch
          source: >
            const response = await
            fetch("https://api.deerapi.com/v1beta/models/gemini-3.1-flash-image-preview:generateContent",
            {
              method: "POST",
              headers: {
                Authorization: `Bearer ${process.env.DEERAPI_KEY}`,
                "Content-Type": "application/json",
              },
              body: JSON.stringify({
                "contents": [
                  {
                    "role": "user",
                    "parts": [
                      {
                        "text": "A Monarch butterfly anatomical sketch on textured parchment, Da Vinci style"
                      }
                    ]
                  }
                ],
                "generationConfig": {
                  "responseModalities": [
                    "TEXT",
                    "IMAGE"
                  ],
                  "imageConfig": {
                    "aspectRatio": "1:1",
                    "imageSize": "4K"
                  }
                }
              }),
            });


            console.log(await response.json());
components:
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      description: Use a DeerAPI API Key as a Bearer token.

````