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

# Nano Banana 2.1 图像编辑

> Nano Banana 2.1 图像编辑 API 通过文字指令和参考图编辑一张图像。

> [!TIP]
>
> 1. 提交后会返回 `task_id`。如果提供了 `callback_url`，当任务状态变为 `finished` 或 `failed` 时，系统会向 `callback_url` 发送 POST 请求。
> 2. 无论是否提供 `callback_url`，都可以通过统一的[查询任务状态](https://docs.vidgo.ai/zh/api-manual/task-management/status.md)接口获取结果。

## 可选参数

* `size` (string)：输出宽高比。auto 跟随参考图。可选值：`auto`、`1:1`、`2:3`、`3:2`、`3:4`、`4:3`、`4:5`、`5:4`、`9:16`、`16:9`、`21:9`。默认：`auto`。
* `resolution` (string)：输出分辨率档位。可选值：`1K`、`2K`、`4K`。默认：`1K`。

## 使用指南

使用 Nano Banana 2.1，通过文字指令和参考图编辑一张图像。

* 将 `model` 设为 `google/nano-banana-2.1/edit`。
* `model` 和可选的 `callback_url` 放在请求根级；工作流参数放在 `input` 内。
* 每次请求生成一张图像。
* 如只需根据提示词生成，请使用[文生图](https://docs.vidgo.ai/zh/api-manual/image-series/nano-banana-2-1-text-to-image.md)，并设置 `model=google/nano-banana-2.1/text-to-image`。

## 参数详情

* `prompt` 必填。提供非空文本，最多 20,000 个字符。
* `image_urls` 必填，接受 1 到 10 个参考图 URL。使用公开可访问的 HTTP(S) URL，顺序与提示词中引用参考图的顺序一致。
* `size` 默认 `auto`。`auto` 跟随参考图的宽高比。

## 计费

按输出图像计费，取决于 `resolution`。在每个档位上，文生图和图像编辑的计费标准相同。

积分在提交时扣除，任务失败会退还。


## OpenAPI

````yaml zh/api-manual/image-series/nano-banana-2-1-edit.json POST /api/generate/submit
openapi: 3.0.0
info:
  title: Vidgo API - Nano Banana 2.1 图像编辑
  description: 使用 Nano Banana 2.1，通过文字指令和参考图编辑一张图像。
  version: 1.0.0
servers:
  - url: https://api.vidgo.ai
    description: 生产环境服务器
security:
  - BearerAuth: []
paths:
  /api/generate/submit:
    post:
      tags:
        - Nano Banana 2.1 Image Edit
      summary: 提交 Nano Banana 2.1 图像编辑任务
      operationId: submitNanoBanana21ImageEditTask
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/SubmitRequest'
            examples:
              reference-edit:
                summary: 使用参考图编辑
                value:
                  model: google/nano-banana-2.1/edit
                  input:
                    prompt: >-
                      Preserve the product and replace the background with a
                      warm modern studio.
                    image_urls:
                      - https://cdn.vidgo.ai/temp/reference-product.png
                    size: auto
                    resolution: 1K
      responses:
        '200':
          description: 任务提交结果。任务 ID 标识一项异步任务；生成可能仍在进行中。
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/SubmitResponse'
        '400':
          description: 请求参数无效
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '401':
          description: 未授权
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
components:
  schemas:
    SubmitRequest:
      type: object
      required:
        - model
        - input
      additionalProperties: false
      properties:
        model:
          type: string
          example: google/nano-banana-2.1/edit
        callback_url:
          type: string
          format: uri
          description: 可选的 Webhook URL，用于接收完成或失败通知。
          example: https://your-domain.com/callback
        input:
          type: object
          required:
            - prompt
            - image_urls
          additionalProperties: false
          properties:
            prompt:
              type: string
              minLength: 1
              maxLength: 20000
              description: |-
                描述编辑内容的文字指令。

                至少包含一个非空白字符。
            size:
              type: string
              description: |-
                输出宽高比。

                auto 跟随参考图。
              enum:
                - auto
                - '1:1'
                - '2:3'
                - '3:2'
                - '3:4'
                - '4:3'
                - '4:5'
                - '5:4'
                - '9:16'
                - '16:9'
                - '21:9'
              default: auto
            resolution:
              type: string
              enum:
                - 1K
                - 2K
                - 4K
              default: 1K
              description: 输出分辨率档位。
            image_urls:
              type: array
              minItems: 1
              maxItems: 10
              items:
                type: string
                format: uri
                description: 使用公开可访问的 HTTP(S) 下载 URL。
              description: 编辑所需的参考图，按提示词中的顺序排列。
    SubmitResponse:
      type: object
      required:
        - code
        - data
      properties:
        code:
          type: integer
          example: 200
        data:
          type: object
          required:
            - task_id
            - status
            - created_time
          properties:
            task_id:
              type: string
              example: task-example-001
            status:
              type: string
              example: running
            created_time:
              type: string
              format: date-time
              example: '2026-10-09T10:30:00'
    ErrorResponse:
      type: object
      required:
        - code
        - error
      properties:
        code:
          type: integer
          example: 400
        error:
          type: object
          properties:
            message:
              type: string
              example: Invalid request parameters
            type:
              type: string
              example: invalid_request_error
  securitySchemes:
    BearerAuth:
      type: http
      scheme: bearer
      bearerFormat: API Key
      description: '使用 `Authorization: Bearer VIDGO_API_KEY`。'

````

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