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

# Gemini Nano Banana 2.1

> Gemini Nano Banana 2.1 圖片生成與對話式編輯，包含原生請求欄位及模型限制。

Gemini Nano Banana 2.1 面向圖片生成與對話式編輯，強化畫質、文字渲染、參考一致性和寬幅圖片能力。使用 `gemini-nano-banana-2.1`，不要替換為僅輸出文本的 Gemini 型號。

## 模型資訊

| 欄位 | 說明 |
| - | - |
| `model` | gemini-nano-banana-2.1 |
| `input limit` | 131,072 tokens |
| `output limit` | 32,768 tokens |
| `input / output` | 輸入文本、影像、影片和 PDF；輸出影像和文本，不輸出原生音訊。 |
| `image output` | 1K（預設）、2K、4K，不沿用 Nano Banana 2 的 512 檔位。 |

以上為模型規格；路由可用性、計費、檔案訪問許可權和請求大小限制取決於所選渠道。圖片輸出使用下方原生 Gemini 介面。

`POST https://api.mixroute.ai/v1/models/gemini-nano-banana-2.1:generateContent`

`POST https://api.mixroute.ai/v1/models/gemini-nano-banana-2.1:streamGenerateContent?alt=sse`

## 生成圖片

```bash theme={null}
curl --request POST "https://api.mixroute.ai/v1/models/gemini-nano-banana-2.1:generateContent" \
  --header "Authorization: Bearer $MIXROUTE_API_KEY" \
  --header "Content-Type: application/json" \
  --data '{
  "contents": [
    {
      "role": "user",
      "parts": [
        {
          "text": "Generate a clean product photograph of a red ceramic mug on a plain white background. No text."
        }
      ]
    }
  ],
  "generationConfig": {
    "responseModalities": [
      "TEXT",
      "IMAGE"
    ],
    "imageConfig": {
      "aspectRatio": "1:1",
      "imageSize": "1K"
    },
    "thinkingConfig": {
      "thinkingLevel": "MINIMAL"
    }
  }
}'
```

在本介面使用原生 `generationConfig.imageConfig` 控制尺寸和比例，不新增 metadata、asset、OpenAI size/n 或請求體 model 欄位；模型由 URL 指定。

## 請求欄位

| 欄位 | 說明 |
| - | - |
| `contents` | 必填，包含 parts 的 user/model 會話輪次。 |
| `contents[].parts[].text` | 提示詞或編輯指令。 |
| `contents[].parts[].inlineData` | 輸入圖片物件，包含 mimeType 和原始 Base64 data，不加 data URI 字首。 |
| `contents[].parts[].fileData` | 原生 fileUri/mimeType 引用，資源必須可被路由賬號訪問。 |
| `generationConfig.responseModalities` | 圖片輸出使用 \["TEXT","IMAGE"] 或 \["IMAGE"]。 |
| `generationConfig.imageConfig.aspectRatio` | 原生比例字串，例如 1:1 或 16:9。 |
| `generationConfig.imageConfig.imageSize` | 1K、2K、4K，大小寫敏感，預設 1K。 |
| `generationConfig.thinkingConfig.thinkingLevel` | MINIMAL、MEDIUM（預設）、HIGH。 |
| `generationConfig.thinkingConfig.includeThoughts` | 可選思考摘要；儲存最終圖片時跳過 thought=true 的內容塊。 |
| `generationConfig.maxOutputTokens` | 圖片與文本共用的輸出預算，最多 32,768；過低可能導致圖片不完整。 |
| `tools` | 路由允許時可用原生 Google Search grounding；該圖片模型不支援函式呼叫。 |
| `safetySettings` | 原生 category/threshold 設定，受廠商和賬號安全策略約束。 |

## 使用限制

* 比例包括 `1:1`、`1:4`、`4:1`、`1:8`、`8:1`、`2:3`、`3:2`、`3:4`、`4:3`、`4:5`、`5:4`、`9:16`、`16:9`、`21:9`。
* 最多 14 張參考圖，模型能力說明覆蓋最多 4 個角色和 10 個物體；輸入上限不代表一致性絕對保證。
* Vertex 內聯影像每張最多 7 MB，支援 PNG、JPEG、WebP、HEIC、HEIF；其他請求限制可能更嚴格。
* 不傳入不支援的取樣或隨機性欄位 temperature、topP、topK、seed、logprobs。
* 不支援音訊生成、任意函式呼叫或結構化 JSON 輸出。

## 編輯與多輪呼叫

```json theme={null}
{
  "contents": [
    {
      "role": "user",
      "parts": [
        {
          "text": "Change the mug color to blue while preserving its shape and the white background."
        },
        {
          "inlineData": {
            "mimeType": "image/png",
            "data": "BASE64_IMAGE_DATA"
          }
        }
      ]
    }
  ],
  "generationConfig": {
    "responseModalities": [
      "TEXT",
      "IMAGE"
    ],
    "imageConfig": {
      "aspectRatio": "1:1",
      "imageSize": "1K"
    },
    "thinkingConfig": {
      "thinkingLevel": "MINIMAL"
    }
  }
}
```

將 BASE64\_IMAGE\_DATA 替換為源圖的 Base64 資料。多輪編輯時，將之前完整的 candidate.content 保留為 model 輪次，再追加下一條 user 訊息。原樣保留所有 thoughtSignature，不要將含圖片的歷史縮減為純文本。

## 讀取輸出

按型別處理 candidates\[].content.parts\[]。依據 MIME 型別解碼並儲存非 thought 的 inlineData 圖片，文本部分單獨讀取。沒有圖片時檢查 promptFeedback 和 finishReason，HTTP 成功不等於一定生成圖片。

流式請求使用 streamGenerateContent?alt=sse 和相同請求體，不在 JSON 中新增 stream 開關。解析 SSE data 事件，逐個處理 JSON 中的圖片和文本內容塊。

[圖片生成與編輯](/zh-hant/api-reference/endpoint/nano-banana) | [圖片流式輸出](/zh-hant/api-reference/endpoint/nano-banana-stream)


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