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

# Gemini Nano Banana 2.1 图像生成

> Gemini Nano Banana 2.1 普通版和 VIP 共用图片生成接口, 支持最多 14 张参考图和 1K, 2K, 4K 分辨率.

<Note>
  **中国大陆用户请注意:** 请使用 `https://toapis.cn` 作为 Base URL. 将以下示例中的 `https://toapis.com` 替换为 `https://toapis.cn`.
</Note>

## 模型选择

| 版本 | Model ID |
| - | - |
| 普通版 | `gemini-nano-banana-2.1` |
| VIP | `gemini-nano-banana-2.1-vip` |

两个模型使用相同的接口和请求参数, 仅通过 `model` 字段切换. 支持文生图和图生图. 请求异步执行, 提交成功后通过任务 ID 查询结果.

<Warning>
  `image_urls` 只接收公开可访问的图片 URL, 不接收 base64 数据. 请先使用 [上传图片接口](../../uploads/images) 上传本地图片并获取 URL.
</Warning>

## 认证

<ParamField header="Authorization" type="string" required>
  所有请求均需要 Bearer Token. 请在 [API Key 管理页面](https://toapis.com/console/token) 获取 API Key.

  ```text theme={null}
  Authorization: Bearer YOUR_API_KEY
  ```
</ParamField>

## 请求参数

<ParamField body="model" type="string" default="gemini-nano-banana-2.1" required>
  模型名称. 使用 `gemini-nano-banana-2.1` 或 `gemini-nano-banana-2.1-vip`.
</ParamField>

<ParamField body="prompt" type="string" required>
  图像生成或编辑的文本描述.
</ParamField>

<ParamField body="size" type="string">
  输出图像的宽高比. 支持以下值:

  * `1:1`
  * `3:2`, `2:3`
  * `4:3`, `3:4`
  * `16:9`, `9:16`
  * `5:4`, `4:5`
  * `21:9`
  * `1:4`, `4:1`
  * `1:8`, `8:1`
</ParamField>

<ParamField body="n" type="integer" default={1}>
  输出数量固定为数字 `1`, 不要使用字符串 `"1"`.
</ParamField>

<ParamField body="image_urls" type="string[]">
  参考图片 URL 字符串数组, 用于图生图或图像编辑. 最多 14 张图片, 每个 URL 必须公开可访问. 参考图数量不代表输出图片数量.

  单张图片不超过 10MB. 支持 .jpeg, .jpg, .png, .webp.

  ```json theme={null}
  ["https://example.com/photo.jpg"]
  ```
</ParamField>

<ParamField body="metadata" type="object">
  额外配置参数.

  <Expandable title="metadata">
    <ParamField body="resolution" type="string" default="1K">
      输出图像分辨率. 支持 `1K`, `2K`, `4K`, 默认 `1K`. 请使用大写 `K`.
    </ParamField>
  </Expandable>
</ParamField>

## 响应字段

<ResponseField name="id" type="string">
  任务 ID, 用于查询任务状态和结果.
</ResponseField>

<ResponseField name="object" type="string">
  固定为 `generation.task`.
</ResponseField>

<ResponseField name="model" type="string">
  请求中使用的模型 ID.
</ResponseField>

<ResponseField name="status" type="string">
  任务状态: `queued`, `in_progress`, `completed`, `failed`.
</ResponseField>

<ResponseField name="progress" type="integer">
  任务进度百分比, 范围为 0-100.
</ResponseField>

<ResponseField name="created_at" type="integer">
  任务创建时间, Unix 时间戳, 单位为秒.
</ResponseField>

<ResponseField name="metadata" type="object">
  任务元数据.
</ResponseField>

<RequestExample>
  ```bash cURL theme={null}
  curl --request POST \
    --url https://toapis.com/v1/images/generations \
    --header 'Authorization: Bearer YOUR_API_KEY' \
    --header 'Content-Type: application/json' \
    --data '{
    "model": "gemini-nano-banana-2.1",
    "prompt": "赛博朋克风格的城市夜景, 霓虹灯闪烁",
    "size": "16:9",
    "n": 1,
    "metadata": {
      "resolution": "2K"
    }
  }'
  ```

  ```bash cURL (VIP 图生图) theme={null}
  curl --request POST \
    --url https://toapis.com/v1/images/generations \
    --header 'Authorization: Bearer YOUR_API_KEY' \
    --header 'Content-Type: application/json' \
    --data '{
    "model": "gemini-nano-banana-2.1-vip",
    "prompt": "将这张照片改为水彩画风格",
    "size": "1:1",
    "n": 1,
    "image_urls": [
      "https://example.com/photo.jpg"
    ],
    "metadata": {
      "resolution": "2K"
    }
  }'
  ```

  ```python Python theme={null}
  import requests

  response = requests.post(
      "https://toapis.com/v1/images/generations",
      headers={
          "Authorization": "Bearer YOUR_API_KEY",
          "Content-Type": "application/json"
      },
      json={
          "model": "gemini-nano-banana-2.1",
          "prompt": "赛博朋克风格的城市夜景, 霓虹灯闪烁",
          "size": "16:9",
          "n": 1,
          "metadata": {
              "resolution": "2K"
          }
      }
  )
  response.raise_for_status()
  task = response.json()
  print(task["id"])
  ```

  ```javascript JavaScript theme={null}
  const response = await fetch('https://toapis.com/v1/images/generations', {
    method: 'POST',
    headers: {
      'Authorization': 'Bearer YOUR_API_KEY',
      'Content-Type': 'application/json'
    },
    body: JSON.stringify({
      "model": "gemini-nano-banana-2.1",
      "prompt": "赛博朋克风格的城市夜景, 霓虹灯闪烁",
      "size": "16:9",
      "n": 1,
      "metadata": {
        "resolution": "2K"
      }
    })
  });

  if (!response.ok) {
    throw new Error(await response.text());
  }
  const task = await response.json();
  console.log(task.id);
  ```
</RequestExample>

<ResponseExample>
  ```json 200 theme={null}
  {
    "id": "task_img_abc123def456",
    "object": "generation.task",
    "model": "gemini-nano-banana-2.1",
    "status": "queued",
    "progress": 0,
    "created_at": 1703884800,
    "metadata": {}
  }
  ```
</ResponseExample>

## 查询结果

提交响应中的 `id` 是任务 ID. 使用 [图片任务查询接口](../../tasks/image-status) 获取任务状态和最终图片. 异步通知请参考 [Webhook 回调](../../webhooks/task-webhooks).


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