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

# 生成图片

> 在 `contents` 中传提示词和参考图，生成的图片以 Base64 出现在 `candidates[].content.parts[].inlineData` 中，模型也可能同时返回文字。请求是同步的，通常需要 5 ~ 60 秒。



## OpenAPI

````yaml /openapi/zh/gemini-nano-banana-2-1.json post /v1beta/models/gemini-nano-banana-2.1:generateContent
openapi: 3.1.0
info:
  description: Nano Banana 2.1：Google 最新的高效率图像生成与对话式编辑模型，画质和文字渲染更好，最高 4K。
  title: Gemini Nano Banana 2.1
  version: v1beta
servers:
  - url: https://api.dreamto.ai
security:
  - bearerAuth: []
  - googApiKey: []
tags:
  - name: Gemini Nano Banana 2.1
paths:
  /v1beta/models/gemini-nano-banana-2.1:generateContent:
    post:
      tags:
        - Gemini Nano Banana 2.1
      summary: 生成图片
      description: >-
        在 `contents` 中传提示词和参考图，生成的图片以 Base64 出现在
        `candidates[].content.parts[].inlineData` 中，模型也可能同时返回文字。请求是同步的，通常需要 5 ~
        60 秒。
      operationId: geminiImageGenerateContent
      requestBody:
        content:
          application/json:
            examples:
              文生图:
                description: 在 `contents` 中传提示词，用 `imageConfig` 指定宽高比。
                summary: 文生图
                value:
                  contents:
                    - role: user
                      parts:
                        - text: 一家以香蕉为主题的高级餐厅里的一道精致甜点，柔和灯光，美食摄影
                  generationConfig:
                    responseModalities:
                      - TEXT
                      - IMAGE
                    imageConfig:
                      aspectRatio: '16:9'
                      imageSize: 2K
              图片编辑（Base64）:
                description: 用 `inlineData` 传入待编辑图片的 Base64 数据，提示词描述修改内容。
                summary: 图片编辑（Base64）
                value:
                  contents:
                    - role: user
                      parts:
                        - text: 把背景换成雨后的霓虹街道，人物保持不变
                        - inlineData:
                            mimeType: image/png
                            data: <BASE64_IMAGE_DATA>
                  generationConfig:
                    responseModalities:
                      - TEXT
                      - IMAGE
                    imageConfig:
                      aspectRatio: '1:1'
                      imageSize: 1K
              图片编辑（图片链接）:
                description: 用 `fileData.fileUri` 传公网可访问的 `https` 图片链接。
                summary: 图片编辑（图片链接）
                value:
                  contents:
                    - role: user
                      parts:
                        - text: 修复键盘顶端的斑驳痕迹，其他内容不变
                        - fileData:
                            fileUri: https://your-cdn.example.com/keyboard.png
                  generationConfig:
                    responseModalities:
                      - TEXT
                      - IMAGE
                    imageConfig:
                      aspectRatio: '4:3'
                      imageSize: 1K
              多图合成:
                description: 按顺序传多张参考图，在提示词中说明每张图的用途；4K 输出。
                summary: 多图合成
                value:
                  contents:
                    - role: user
                      parts:
                        - text: 让第一张图中的模特穿上第二张图里的连衣裙，户外自然光，全身照
                        - fileData:
                            fileUri: https://your-cdn.example.com/model.png
                        - fileData:
                            fileUri: https://your-cdn.example.com/dress.png
                  generationConfig:
                    responseModalities:
                      - TEXT
                      - IMAGE
                    imageConfig:
                      aspectRatio: '9:16'
                      imageSize: 4K
            schema:
              $ref: '#/components/schemas/GeminiImageRequest'
        required: true
      responses:
        '200':
          content:
            application/json:
              examples:
                example:
                  value:
                    candidates:
                      - content:
                          role: model
                          parts:
                            - inlineData:
                                mimeType: image/png
                                data: <BASE64_IMAGE_DATA>
                        finishReason: STOP
                        index: 0
                    usageMetadata:
                      promptTokenCount: 18
                      candidatesTokenCount: 1120
                      totalTokenCount: 1138
                      promptTokensDetails:
                        - modality: TEXT
                          tokenCount: 18
                      candidatesTokensDetails:
                        - modality: IMAGE
                          tokenCount: 1120
                    modelVersion: gemini-nano-banana-2.1
                    responseId: 8bQWadqLHo-vz7IPpLWdkQ4
              schema:
                $ref: '#/components/schemas/GeminiImageResponse'
          description: 生成成功。
          headers:
            X-Request-Id:
              description: 本次请求的 ID，排查问题时请提供。
              schema:
                type: string
        '400':
          content:
            application/json:
              examples:
                example:
                  value:
                    error:
                      code: invalid_request
                      http_status: 400
                      message: Invalid request.
                      request_id: req_7c1e9a4b2d3f5a6b8c9d0e1f
                      type: invalid_request_error
              schema:
                $ref: '#/components/schemas/ImageAPIErrorResponse'
          description: 参数错误：缺少必填参数、取值不合法或传入了不支持的参数。不扣费。
        '401':
          content:
            application/json:
              examples:
                example:
                  value:
                    error:
                      code: unauthorized
                      http_status: 401
                      message: Unauthorized.
                      request_id: req_7c1e9a4b2d3f5a6b8c9d0e1f
                      type: authentication_error
              schema:
                $ref: '#/components/schemas/ImageAPIErrorResponse'
          description: API Key 缺失或无效。
        '402':
          content:
            application/json:
              examples:
                example:
                  value:
                    error:
                      code: insufficient_balance
                      http_status: 402
                      message: Insufficient balance.
                      request_id: req_7c1e9a4b2d3f5a6b8c9d0e1f
                      type: insufficient_balance_error
              schema:
                $ref: '#/components/schemas/ImageAPIErrorResponse'
          description: 余额不足。
        '429':
          content:
            application/json:
              examples:
                example:
                  value:
                    error:
                      code: rate_limit_exceeded
                      http_status: 429
                      message: Rate limit exceeded. Please try again later.
                      request_id: req_7c1e9a4b2d3f5a6b8c9d0e1f
                      type: rate_limit_error
              schema:
                $ref: '#/components/schemas/ImageAPIErrorResponse'
          description: 请求过于频繁，请稍后重试。
        '502':
          content:
            application/json:
              examples:
                example:
                  value:
                    error:
                      code: service_unavailable
                      http_status: 502
                      message: Service temporarily unavailable. Please try again later.
                      request_id: req_7c1e9a4b2d3f5a6b8c9d0e1f
                      type: api_error
              schema:
                $ref: '#/components/schemas/ImageAPIErrorResponse'
          description: 上游生成失败（含内容审核拒绝），不扣费，可重试。
components:
  schemas:
    GeminiImageRequest:
      additionalProperties: false
      description: generateContent 请求体。
      properties:
        contents:
          description: 对话内容。单轮请求传一个 `user` 内容；多轮编辑时按顺序传历史轮次。
          items:
            $ref: '#/components/schemas/GeminiImageContent'
          type: array
        generationConfig:
          $ref: '#/components/schemas/GeminiImageGenerationConfig'
          description: 生成配置。
      required:
        - contents
      type: object
    GeminiImageResponse:
      additionalProperties: false
      description: generateContent 响应。
      properties:
        candidates:
          description: 生成结果，通常只有一个。
          items:
            $ref: '#/components/schemas/GeminiImageCandidate'
          type: array
        usageMetadata:
          $ref: '#/components/schemas/GeminiImageUsage'
          description: Token 用量。
        modelVersion:
          description: 生成所用的模型版本。
          type: string
        responseId:
          description: 响应 ID。
          type: string
      required:
        - candidates
      type: object
    ImageAPIErrorResponse:
      additionalProperties: false
      description: 错误响应。
      properties:
        error:
          $ref: '#/components/schemas/ImageAPIError'
          description: 错误信息。
      required:
        - error
      type: object
    GeminiImageContent:
      additionalProperties: false
      description: 一轮对话内容。
      properties:
        role:
          description: |-
            发言方，默认 `user`。

            **可选值：**
            - `user`：用户。
            - `model`：模型（多轮编辑时的历史回复）。
          enum:
            - user
            - model
          type: string
        parts:
          description: 内容片段：文字和图片按顺序排列，每个片段只填 `text`、`inlineData`、`fileData` 之一。
          items:
            $ref: '#/components/schemas/GeminiImagePart'
          type: array
      required:
        - parts
      type: object
    GeminiImageGenerationConfig:
      additionalProperties: false
      description: 生成配置。
      properties:
        responseModalities:
          description: |-
            返回的内容类型，默认图文混合；只要图片时传 `["IMAGE"]`。

            **可选值：**
            - `TEXT`：文字。
            - `IMAGE`：图片。
          items:
            enum:
              - TEXT
              - IMAGE
            type: string
          type: array
        imageConfig:
          $ref: '#/components/schemas/GeminiImageConfig'
          description: 图片输出配置。
      type: object
    GeminiImageCandidate:
      additionalProperties: false
      description: 一个生成结果。
      properties:
        content:
          $ref: '#/components/schemas/GeminiImageOutputContent'
          description: 生成的内容。
        finishReason:
          description: |-
            结束原因。

            **可选值：**
            - `STOP`：正常结束。
            - `MAX_TOKENS`：达到输出 Token 上限。
            - `SAFETY`：因安全原因中止。
            - `PROHIBITED_CONTENT`：内容违反使用政策。
            - `IMAGE_SAFETY`：生成的图片未通过安全检查。
            - `IMAGE_PROHIBITED_CONTENT`：生成的图片包含违禁内容。
            - `NO_IMAGE`：模型没有生成图片，可调整提示词后重试。
            - `OTHER`：其他原因。
          enum:
            - STOP
            - MAX_TOKENS
            - SAFETY
            - PROHIBITED_CONTENT
            - IMAGE_SAFETY
            - IMAGE_PROHIBITED_CONTENT
            - NO_IMAGE
            - OTHER
          type: string
        index:
          description: 结果序号，从 0 开始。
          format: int64
          type: integer
      required:
        - content
        - index
      type: object
    GeminiImageUsage:
      additionalProperties: false
      description: Token 用量。
      properties:
        promptTokenCount:
          description: 输入 Token 数（文字 + 图片）。
          format: int64
          type: integer
        candidatesTokenCount:
          description: 输出 Token 数。
          format: int64
          type: integer
        thoughtsTokenCount:
          description: 思考 Token 数。
          format: int64
          type: integer
        totalTokenCount:
          description: Token 总数。
          format: int64
          type: integer
        promptTokensDetails:
          description: 输入 Token 按类型明细。
          items:
            $ref: '#/components/schemas/GeminiImageTokenCount'
          type: array
        candidatesTokensDetails:
          description: 输出 Token 按类型明细。
          items:
            $ref: '#/components/schemas/GeminiImageTokenCount'
          type: array
      required:
        - promptTokenCount
        - candidatesTokenCount
        - totalTokenCount
      type: object
    ImageAPIError:
      additionalProperties: false
      description: 错误信息。
      properties:
        code:
          description: 错误码。
          type: string
        http_status:
          description: HTTP 状态码。
          format: int64
          type: integer
        message:
          description: 可读的错误说明。
          type: string
        request_id:
          description: 请求 ID，排查问题时请提供。
          type: string
        type:
          description: |-
            错误类型。

            **可选值：**
            - `invalid_request_error`：请求参数错误。
            - `authentication_error`：认证失败。
            - `insufficient_balance_error`：余额不足。
            - `permission_error`：无权限。
            - `rate_limit_error`：请求过于频繁。
            - `api_error`：服务端或上游错误。
          enum:
            - invalid_request_error
            - authentication_error
            - insufficient_balance_error
            - permission_error
            - rate_limit_error
            - api_error
          type: string
      required:
        - code
        - http_status
        - message
        - request_id
        - type
      type: object
    GeminiImagePart:
      additionalProperties: false
      description: 一个内容片段。
      properties:
        text:
          description: 文字（提示词）。
          type: string
        inlineData:
          $ref: '#/components/schemas/GeminiImageInlineData'
          description: 以 Base64 内联的图片。
        fileData:
          $ref: '#/components/schemas/GeminiImageFileData'
          description: 以链接引用的图片。
      type: object
    GeminiImageConfig:
      additionalProperties: false
      description: 图片输出配置。
      properties:
        aspectRatio:
          description: |-
            输出宽高比。不传时文生图为 `1:1`，编辑时与输入图一致。

            **可选值：**
            - `1:1`：正方形，1K 为 1024x1024。
            - `1:4`：超长竖版，1K 为 512x2048。
            - `1:8`：极长竖版，1K 为 384x3072。
            - `2:3`：竖版，1K 为 848x1264。
            - `3:2`：横版，1K 为 1264x848。
            - `3:4`：竖版，1K 为 896x1200。
            - `4:1`：超宽横版，1K 为 2048x512。
            - `4:3`：横版，1K 为 1200x896。
            - `4:5`：竖版，1K 为 928x1152。
            - `5:4`：横版，1K 为 1152x928。
            - `8:1`：极宽横版，1K 为 3072x384。
            - `9:16`：竖屏，1K 为 768x1376。
            - `16:9`：宽屏，1K 为 1376x768。
            - `21:9`：超宽屏，1K 为 1584x672。
          enum:
            - '1:1'
            - '1:4'
            - '1:8'
            - '2:3'
            - '3:2'
            - '3:4'
            - '4:1'
            - '4:3'
            - '4:5'
            - '5:4'
            - '8:1'
            - '9:16'
            - '16:9'
            - '21:9'
          type: string
        imageSize:
          description: |-
            输出分辨率档位，默认 `1K`，`K` 必须大写（小写会被拒绝）。

            **可选值：**
            - `1K`：1K（默认），如 1:1 为 1024x1024。
            - `2K`：2K，如 1:1 为 2048x2048。
            - `4K`：4K，如 1:1 为 4096x4096。
          enum:
            - 1K
            - 2K
            - 4K
          type: string
      type: object
    GeminiImageOutputContent:
      additionalProperties: false
      description: 模型输出内容。
      properties:
        role:
          description: |-
            固定为 `model`。

            **可选值：**
            - `user`：用户。
            - `model`：模型（多轮编辑时的历史回复）。
          enum:
            - user
            - model
          type: string
        parts:
          description: 输出片段：文字和图片按顺序排列。
          items:
            $ref: '#/components/schemas/GeminiImageOutputPart'
          type: array
      required:
        - role
        - parts
      type: object
    GeminiImageTokenCount:
      additionalProperties: false
      description: 某一类型的 Token 数。
      properties:
        modality:
          description: |-
            类型。

            **可选值：**
            - `TEXT`：文字。
            - `IMAGE`：图片。
          enum:
            - TEXT
            - IMAGE
          type: string
        tokenCount:
          description: Token 数。
          format: int64
          type: integer
      required:
        - modality
        - tokenCount
      type: object
    GeminiImageInlineData:
      additionalProperties: false
      description: 内联图片数据。
      properties:
        mimeType:
          description: |-
            图片 MIME 类型。

            **可选值：**
            - `image/png`：PNG。
            - `image/jpeg`：JPEG。
            - `image/webp`：WebP。
            - `image/heic`：HEIC。
            - `image/heif`：HEIF。
          enum:
            - image/png
            - image/jpeg
            - image/webp
            - image/heic
            - image/heif
          type: string
        data:
          description: 图片的 Base64 数据（不含 `data:` 前缀）。
          type: string
      required:
        - mimeType
        - data
      type: object
    GeminiImageFileData:
      additionalProperties: false
      description: 图片链接。
      properties:
        fileUri:
          description: 公网可直接下载的 `https` 图片链接。
          type: string
      required:
        - fileUri
      type: object
    GeminiImageOutputPart:
      additionalProperties: false
      description: 一个输出片段。
      properties:
        text:
          description: 模型返回的文字。
          type: string
        inlineData:
          $ref: '#/components/schemas/GeminiImageOutputInlineData'
          description: 生成的图片。
        thought:
          description: 为 `true` 时该片段是思考过程，不是最终结果。
          type: boolean
        thoughtSignature:
          description: 思考签名。多轮编辑时把模型返回的片段原样放回 `contents` 即可。
          type: string
      type: object
    GeminiImageOutputInlineData:
      additionalProperties: false
      description: 图片数据。
      properties:
        mimeType:
          description: 图片 MIME 类型，如 `image/png`。
          type: string
        data:
          description: 图片的 Base64 数据。
          type: string
      required:
        - mimeType
        - data
      type: object
  securitySchemes:
    bearerAuth:
      description: 'DreamTo 控制台创建的 API Key，格式 `Authorization: Bearer <API Key>`。'
      scheme: bearer
      type: http
    googApiKey:
      description: 也可以把 DreamTo API Key 放在 `x-goog-api-key` 请求头，Google 官方 SDK 默认使用这种方式。
      in: header
      name: x-goog-api-key
      type: apiKey

````

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.