# Gemini  generates image

## OpenAPI Specification

```yaml
openapi: 3.0.1
info:
  title: ''
  description: ''
  version: 1.0.0
paths:
  /v1beta/models/{model}:generateContent:
    post:
      summary: Gemini  generates image
      deprecated: false
      description: >-
        Gemini Native Format Raw Graph, guide refer to:
        https://apidoc.cometapi.com/guide-to-calling-gemini-2-5-flash-image-1425263m0


        ## 🎉 Nano Banana 2 Image(`gemini-3.1-flash-image-preview`) Now
        Supported!


        we highly recommend reading the official Gemini documentation:


        👉 https://ai.google.dev/gemini-api/docs/image-generation


        You only need to replace `https://generativelanguage.googleapis.com`
        with `https://api.cometapi.com`


        **Generate images up to 4K resolution Example:**

        ```bash

        curl -s -X POST \
          "https://api.cometapi.com/v1beta/models/gemini-3-pro-image-preview:generateContent" \
          -H "x-goog-api-key: $COMETAPI_KEY" \
          -H "Content-Type: application/json" \
          -d '{
            "contents": [{"parts": [{"text": "Da Vinci style anatomical sketch of a dissected Monarch butterfly. Detailed drawings of the head, wings, and legs on textured parchment with notes in English."}]}],
            "tools": [{"google_search": {}}],
            "generationConfig": {
              "responseModalities": ["TEXT", "IMAGE"],
              "imageConfig": {"aspectRatio": "1:1", "imageSize": "4K"}
            }
          }' | jq -r '.candidates[0].content.parts[] | select(.inlineData) | .inlineData.data' | head -1 | base64 --decode > butterfly.png
        ```


        **Multi-turn image editing Example:**

        ```bash

        curl -s -X POST \
          "https://api.cometapi.com/v1beta/models/gemini-3-pro-image-preview:generateContent" \
          -H "x-goog-api-key: $COMETAPI_KEY" \
          -H "Content-Type: application/json" \
          -d '{
            "contents": [{
              "role": "user",
              "parts": [
                {"text": "Create a vibrant infographic that explains photosynthesis as if it were a recipe for a plants favorite food. Show the \"ingredients\" (sunlight, water, CO2) and the \"finished dish\" (sugar/energy). The style should be like a page from a colorful kids cookbook, suitable for a 4th grader."}
              ]
            }],
            "generationConfig": {
              "responseModalities": ["TEXT", "IMAGE"]
            }
          }' > turn1_response.json

        cat turn1_response.json

        # Requires jq to parse JSON response

        jq -r '.candidates[0].content.parts[] | select(.inlineData) |
        .inlineData.data' turn1_response.json | head -1 | base64 --decode >
        photosynthesis.png

        ```


        ---


        ## 🍌 Flash 2.5 Image Updates


        ### a. Flexible Aspect Ratios

        Now supports multiple aspect ratio settings for easy content creation
        across different devices. All resolutions consume 1,290 tokens by
        default.


        **Supported aspect ratios:**

        1:1, 3:2, 2:3, 3:4, 4:3, 4:5, 5:4, 9:16, 16:9, 21:9


        **Reference examples:**

        - https://ai.google.dev/gemini-api/docs/image-generation#aspect_ratios

        -
        https://cloud.google.com/vertex-ai/generative-ai/docs/multimodal/image-generation#googlegenaisdk_imggen_mmflash_with_txt-drest

        -
        https://github.com/GoogleCloudPlatform/generative-ai/blob/main/gemini/getting-started/intro_gemini_2_5_image_gen.ipynb


        ### b. Model Name Update

        All new features will be available on the new model ID:
        **`gemini-2.5-flash-image`**. The previous
        `gemini-2.5-flash-image-preview` will be deprecated.


        ⚠️ **Migration required by October 31, 2025**


        ### c. Force Image Output

        To address the frequent issue of text-only outputs, you can now set
        `"responseModalities"` to `["IMAGE"]` only in API requests. This ensures
        image generation without text-only responses.
      tags:
        - 🖼️ Image Models/Gemini
      parameters:
        - name: model
          in: path
          description: Gemini model ID that supports image generation
          required: true
          example: gemini-3.1-flash-image-preview
          schema:
            type: string
            enum:
              - gemini-3-pro-image
              - gemini-3.1-flash-image-preview
            x-apidog-enum:
              - value: gemini-3-pro-image
                name: ''
                description: ''
              - value: gemini-3.1-flash-image-preview
                name: ''
                description: Self-developed model
        - name: Authorization
          in: header
          description: ''
          required: true
          example: '{{api-key}}'
          schema:
            type: string
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                contents:
                  type: array
                  items:
                    type: object
                    properties:
                      parts:
                        type: array
                        items:
                          type: object
                          properties:
                            text:
                              type: string
                              description: >-
                                The specific text content, such as the user's
                                question.
                          x-apidog-orders:
                            - text
                          description: A specific content block, such as a piece of text.
                        description: >-
                          Contains the specific content blocks sent by the role.
                          It is designed as an array to support multimodal input
                          (e.g., including both text and images).
                    x-apidog-orders:
                      - parts
                    description: >-
                      Each item in the array represents a turn (or a message) in
                      the conversation.
                  description: >-
                    Contains the conversation history or the current content to
                    be sent. This is the core field for the conversation.
                tools:
                  type: array
                  items:
                    type: object
                    properties:
                      google_search:
                        type: object
                        properties: {}
                        x-apidog-orders: []
                    x-apidog-orders:
                      - google_search
                generationConfig:
                  type: object
                  properties:
                    responseModalities:
                      type: array
                      items:
                        type: string
                      description: >-
                        (The meaning of this field is uncertain, this is a guess
                        based on the name) Possibly used to specify the expected
                        content modalities (types) for the model's response, for
                        example, to return text only.
                    imageConfig:
                      type: object
                      properties:
                        aspectRatio:
                          type: string
                          description: >-
                            Supports `1:1` `2:3` `3:2` `3:4` `4:3` `4:5` `5:4`
                            `9:16` `16:9` `21:9`, but please refer to the
                            official Gemini documentation for the most accurate
                            information.
                        imageSize:
                          type: string
                          description: Supports `1K`, `2K`, and `4K` parameters.
                      required:
                        - aspectRatio
                        - imageSize
                      x-apidog-orders:
                        - aspectRatio
                        - imageSize
                  required:
                    - responseModalities
                    - imageConfig
                  x-apidog-orders:
                    - responseModalities
                    - imageConfig
                  description: >-
                    Used to configure the model's generation behavior, such as
                    temperature, maximum output length, etc.
              required:
                - contents
                - tools
                - generationConfig
              x-apidog-orders:
                - contents
                - tools
                - generationConfig
              description: The entire request body
            examples:
              '1':
                value:
                  contents:
                    - role: user
                      parts:
                        - text: >-
                            'Maintain the character features in the image to
                            generate a new portrait photo: a woman leaning on a
                            wooden railing of a traditional Chinese building.
                            She is wearing a blue cheongsam with pink and red
                            floral motifs and a headdress made of colorful
                            flowers, including roses and lilacs. Her right hand
                            gently touches a large kite with a blue background,
                            decorated with pink fish motifs and a pair of large
                            eyes. The background is the interior of an old
                            wooden building, dimly lit and cozy. The painting
                            style is realistic, focusing on the textural details
                            of the clothing patterns, floral headdresses, and
                            wooden buildings
                  generationConfig:
                    responseModalities:
                      - IMAGE
                    imageConfig:
                      aspectRatio: '9:16'
                summary: text
              '2':
                value:
                  contents:
                    - role: user
                      parts:
                        - text: Blend three images to output a high-resolution image
                        - inline_data:
                            mime_type: image/jpeg
                            data: <your_first_image_base64_data_here>
                        - inline_data:
                            mime_type: image/jpeg
                            data: <your_second_image_base64_data_here>
                        - inline_data:
                            mime_type: image/jpeg
                            data: <your_third_image_base64_data_here>
                  generationConfig:
                    responseModalities:
                      - TEXT
                      - IMAGE
                summary: images to image
              '3':
                value:
                  contents:
                    - parts:
                        - text: >-
                            Da Vinci style anatomical sketch of a dissected
                            Monarch butterfly. Detailed drawings of the head,
                            wings, and legs on textured parchment with notes in
                            English.
                  tools:
                    - google_search: {}
                  generationConfig:
                    responseModalities:
                      - TEXT
                      - IMAGE
                    imageConfig:
                      aspectRatio: '1:1'
                      imageSize: 4K
                summary: 4K
              '4':
                value:
                  contents:
                    - parts:
                        - text: >-
                            Visualize the current weather forecast for the next
                            5 days in San Francisco as a clean, modern weather
                            chart. Add a visual on what I should wear each day
                  tools:
                    - google_search: {}
                  generationConfig:
                    responseModalities:
                      - TEXT
                      - IMAGE
                    imageConfig:
                      aspectRatio: '16:9'
                      imageSize: 1K
                summary: 2K
              '5':
                value:
                  contents:
                    - parts:
                        - text: >-
                            Da Vinci style anatomical sketch of a dissected
                            Monarch butterfly. Detailed drawings of the head,
                            wings, and legs on textured parchment with notes in
                            English.
                  tools:
                    - google_search: {}
                  generationConfig:
                    responseModalities:
                      - TEXT
                      - IMAGE
                    imageConfig:
                      aspectRatio: '1:1'
                      imageSize: 1K
                summary: 1K
      responses:
        '200':
          description: ''
          content:
            application/json:
              schema:
                type: object
                properties:
                  candidates:
                    type: array
                    items:
                      type: object
                      properties:
                        content:
                          type: object
                          properties:
                            role:
                              type: string
                            parts:
                              type: array
                              items:
                                type: object
                                properties:
                                  text:
                                    type: string
                                x-apidog-orders:
                                  - text
                          required:
                            - role
                            - parts
                          x-apidog-orders:
                            - role
                            - parts
                        finishReason:
                          type: string
                        index:
                          type: integer
                        safetyRatings:
                          type: array
                          items:
                            type: string
                      x-apidog-orders:
                        - content
                        - finishReason
                        - index
                        - safetyRatings
                  promptFeedback:
                    type: object
                    properties:
                      safetyRatings:
                        type: array
                        items:
                          type: string
                    required:
                      - safetyRatings
                    x-apidog-orders:
                      - safetyRatings
                  usageMetadata:
                    type: object
                    properties:
                      promptTokenCount:
                        type: integer
                      candidatesTokenCount:
                        type: integer
                      totalTokenCount:
                        type: integer
                      thoughtsTokenCount:
                        type: integer
                      promptTokensDetails:
                        type: 'null'
                    required:
                      - promptTokenCount
                      - candidatesTokenCount
                      - totalTokenCount
                      - thoughtsTokenCount
                      - promptTokensDetails
                    x-apidog-orders:
                      - promptTokenCount
                      - candidatesTokenCount
                      - totalTokenCount
                      - thoughtsTokenCount
                      - promptTokensDetails
                required:
                  - candidates
                  - promptFeedback
                  - usageMetadata
                x-apidog-orders:
                  - candidates
                  - promptFeedback
                  - usageMetadata
              example:
                candidates:
                  - content:
                      role: model
                      parts:
                        - inlineData:
                            mimeType: image/png
                            data: iVBORw0KGgoAAAA...
                    finishReason: STOP
                usageMetadata:
                  promptTokenCount: 122
                  candidatesTokenCount: 1290
                  totalTokenCount: 1412
                  trafficType: ON_DEMAND
                  promptTokensDetails:
                    - modality: TEXT
                      tokenCount: 122
                  candidatesTokensDetails:
                    - modality: IMAGE
                      tokenCount: 1290
                modelVersion: gemini-2.5-flash-image-preview
                createTime: '2025-11-06T07:06:46.306721Z'
                responseId: BkkMaaHcEsSY4_UP_aOrmAg
          headers: {}
          x-apidog-name: Success
      security: []
      x-apidog-folder: 🖼️ Image Models/Gemini
      x-apidog-status: released
      x-run-in-apidog: https://app.apidog.com/web/project/810968/apis/api-20873272-run
components:
  schemas: {}
  securitySchemes: {}
servers:
  - url: https://api.cometapi.com
    description: Prod Env
security: []

```
