> ## 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.