> ## 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 中的图片和文本内容块。

[图片生成与编辑](/cn/api-reference/endpoint/nano-banana) | [图片流式输出](/cn/api-reference/endpoint/nano-banana-stream)


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