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

# Nano Banana

> 使用 nano-banana 通过 OpenAI Images API 生成和编辑图片

> 更新日期：2026-06-06

# Nano Banana

```
POST /v1/images/generations
```

`nano-banana` 是 `nano-banana` 的公开别名。用户侧统一使用 OpenAI Images 兼容协议；Gemini / Vertex 原生承载、字段转换和路由选择都由 Crazyrouter 在服务端处理。

<Warning>
  图片生成、图片编辑、多参考图这类请求通常耗时较长。生产接入请优先使用主承接线路 `https://api.crazyrouter.com/v1`，完整生成端点为 `https://api.crazyrouter.com/v1/images/generations`。账号登录、充值和控制台仍使用 `https://crazyrouter.com`。
</Warning>

## 模型名

| 推荐模型名         | 等价底层模型        |
| ------------- | ------------- |
| `nano-banana` | `nano-banana` |

推荐在客户代码里使用 `nano-banana`。如果你的系统已经直接写了 `nano-banana`，也可以继续通过同一个 `/v1/images/generations` 入口调用。

## 请求参数

| 参数                   | 类型                 | 必填 | 说明                                  |
| -------------------- | ------------------ | -- | ----------------------------------- |
| `model`              | string             | 是  | 推荐 `nano-banana`；也兼容 `nano-banana`  |
| `prompt`             | string             | 是  | 生成或编辑指令                             |
| `image_input`        | string 或 string\[] | 否  | 参考图 URL；不传则为文生图                     |
| `resolution`         | string             | 否  | `1K`、`2K`、`4K`                      |
| `aspect_ratio`       | string             | 否  | 如 `1:1`、`16:9`、`9:16`、`21:9`、`auto` |
| `output_format`      | string             | 否  | `png`、`jpeg` / `jpg`                |
| `output_compression` | integer            | 否  | `0-100`，用于 JPEG 压缩质量                |
| `n`                  | integer            | 否  | 生成数量，默认 `1`                         |

<Note>
  不要在客户请求里传 Gemini 原生字段，例如 `generationConfig`、`imageConfig`、`imageOutputOptions`、`image_output_options`。这些属于上游 provider 细节，Crazyrouter 会从统一参数自动转换。
</Note>

## 文生图示例

<CodeGroup>
  ```bash cURL theme={null}
  curl -X POST https://api.crazyrouter.com/v1/images/generations \
    -H "Content-Type: application/json" \
    -H "Authorization: Bearer YOUR_API_KEY" \
    -d '{
      "model": "nano-banana",
      "prompt": "A clean banana icon on a white background, minimal product style",
      "resolution": "1K",
      "aspect_ratio": "1:1",
      "output_format": "png"
    }'
  ```

  ```python Python theme={null}
  from openai import OpenAI

  client = OpenAI(
      api_key="YOUR_API_KEY",
      base_url="https://api.crazyrouter.com/v1",
  )

  response = client.images.generate(
      model="nano-banana",
      prompt="A clean banana icon on a white background, minimal product style",
      n=1,
      extra_body={
          "resolution": "1K",
          "aspect_ratio": "1:1",
          "output_format": "png",
      },
  )

  print(response.data[0].url or response.data[0].b64_json)
  ```
</CodeGroup>

## 参考图编辑示例

```bash cURL theme={null}
curl -X POST https://api.crazyrouter.com/v1/images/generations \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -d '{
    "model": "nano-banana",
    "prompt": "保持主体不变，把背景改成白色电商棚拍风格",
    "image_input": [
      "https://example.com/product.png"
    ],
    "resolution": "1K",
    "aspect_ratio": "1:1",
    "output_format": "jpeg",
    "output_compression": 85
  }'
```

## 响应

响应保持 OpenAI Images 风格。默认优先读取 `data[0].url`；少数兼容渠道可能返回 `data[0].b64_json`。

```json theme={null}
{
  "created": 1778990000,
  "data": [
    {
      "url": "https://media.crazyrouter.com/task-artifacts/2026/05/17/sync-image/request-id-1.png"
    }
  ]
}
```

## 常见错误

| 错误写法                                                             | 正确写法                                           |
| ---------------------------------------------------------------- | ---------------------------------------------- |
| 直接调用 `/v1beta/models/nano-banana:generateContent`                | 改用 `POST /v1/images/generations`               |
| 在请求中传 `image_output_options`                                     | 改用统一参数 `output_format`、`output_compression`    |
| 只把 base URL 配成 `https://api.crazyrouter.com` 后又让 SDK 拼 OpenAI 路径 | OpenAI SDK 使用 `https://api.crazyrouter.com/v1` |
