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

# Gemini Nano Banana 2.1

> Nano Banana 2.1：Google 最新的高效率图像生成与对话式编辑模型，画质和文字渲染更好，最高 4K。

`gemini-nano-banana-2.1`（Nano Banana 2.1）是 Google 最新的高效率图像生成与对话式编辑模型，是 [Gemini 3.1 Flash Image](https://docs.dreamto.ai/image/models/gemini-3-1-flash-image.md)（Nano Banana 2）的升级版：保持 Flash 档的速度和成本，各档分辨率的画质和真实感更好，修复了 1:4、4:1、1:8、8:1 等超宽、超长画幅在 2K / 4K 下的拼接瑕疵，文字渲染和信息图排版更准确。支持文生图、对话式多轮编辑和最多 14 张参考图融合（最多 4 个人物、10 个物体保持一致），输出 1K / 2K / 4K。Google 将它定位为 [Gemini 3 Pro Image](https://docs.dreamto.ai/image/models/gemini-3-pro-image.md)（Nano Banana Pro）更高效的替代选择。

## 接入

| | Google 官方 | DreamTo |
| - | - | - |
| 服务地址 | `https://generativelanguage.googleapis.com` | `https://api.dreamto.ai` |
| API Key | Google AI Studio 密钥 | DreamTo 控制台的 API Key，放在 `x-goog-api-key` 或 `Authorization: Bearer` 请求头 |

## 接口

| 接口 | 用途 |
| - | - |
| [`POST /v1beta/models/gemini-nano-banana-2.1:generateContent`](https://docs.dreamto.ai/api-reference/gemini-nano-banana-2-1/generate-content) | 生成图片 |

## 参数范围

| 字段 | 取值 |
| - | - |
| `contents[].parts[].text` | 提示词，描述要生成或修改的内容 |
| `contents[].parts[].inlineData.data` | 参考图 Base64（`mimeType` 为 `image/png` / `image/jpeg` / `image/webp` / `image/heic` / `image/heif`）；最多 14 张，其中最多 10 张物体图、4 张人物图 |
| `contents[].parts[].fileData.fileUri` | 参考图公网 `https` 链接 |
| `generationConfig.imageConfig.aspectRatio` | `1:1` / `1:4` / `1:8` / `2:3` / `3:2` / `3:4` / `4:1` / `4:3` / `4:5` / `5:4` / `8:1` / `9:16` / `16:9` / `21:9`；不传时文生图为 `1:1`，编辑时与输入图一致 |
| `generationConfig.imageConfig.imageSize` | `1K`（默认）/ `2K` / `4K`，`K` 必须大写 |
| `generationConfig.responseModalities` | `["TEXT", "IMAGE"]`（默认，图文混合）或 `["IMAGE"]`（只要图片） |

### 暂不支持的官方参数

传入后返回 400，不调用模型、不扣费。

| 参数 | 说明 |
| - | - |
| `systemInstruction` | 暂不支持系统指令，请写在提示词中 |
| `safetySettings` | 暂不支持自定义安全阈值，使用官方默认值 |
| `tools` | 暂不支持 Google 搜索增强（`google_search`） |

## 计费

按模型价格计费，以控制台显示的价格为准。参数错误和生成失败不扣费。

## 快速开始

示例中的 `$DREAMTO_API_KEY` 为你的 API Key。

```bash cURL theme={null}
curl -X POST "https://api.dreamto.ai/v1beta/models/gemini-nano-banana-2.1:generateContent" \
  -H "Authorization: Bearer $DREAMTO_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "contents": [
      {
        "role": "user",
        "parts": [
          {
            "text": "一家以香蕉为主题的高级餐厅里的一道精致甜点，柔和灯光，美食摄影"
          }
        ]
      }
    ],
    "generationConfig": {
      "responseModalities": [
        "TEXT",
        "IMAGE"
      ],
      "imageConfig": {
        "aspectRatio": "16:9",
        "imageSize": "2K"
      }
    }
  }'
```

```python Python theme={null}
import base64
import os

import requests

URL = "https://api.dreamto.ai/v1beta/models/gemini-nano-banana-2.1:generateContent"
HEADERS = {"x-goog-api-key": os.environ["DREAMTO_API_KEY"]}

payload = {
    "contents": [
        {
            "role": "user",
            "parts": [
                {
                    "text": "一家以香蕉为主题的高级餐厅里的一道精致甜点，柔和灯光，美食摄影"
                }
            ]
        }
    ],
    "generationConfig": {
        "responseModalities": [
            "TEXT",
            "IMAGE"
        ],
        "imageConfig": {
            "aspectRatio": "16:9",
            "imageSize": "2K"
        }
    }
}

response = requests.post(URL, headers=HEADERS, json=payload, timeout=300).json()
for part in response["candidates"][0]["content"]["parts"]:
    if "inlineData" in part:
        with open("output.png", "wb") as f:
            f.write(base64.b64decode(part["inlineData"]["data"]))
    elif "text" in part:
        print(part["text"])
```

## 使用说明

* 本页只覆盖 `generateContent`；暂不支持 Batch API，以及 Files API 上传后的 `files/...` 引用。
* 参考图用 `inlineData` 传 Base64，或用 `fileData.fileUri` 传公网 `https` 链接。
* 错误响应使用 DreamTo 的错误结构（见接口的错误示例），而不是 Google 的 `status` 结构。


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