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

# Nano Banana Pro API：使用 Google 模型生成 4K 图像

> 支持4K输出和多参考编辑的专业Google图像生成API

## 概览

使用Nano Banana Pro将多个参考图像合并为一张图像。对于目录图，将产品和背景图像提供给`image_urls`，在`prompt`中说明需保留的细节，并选择`1K`、`2K`或`4K`作为输出分辨率。从[图生图请求](#image-to-image)开始。

如果您的集成已使用 [Nano Banana](https://apixo.ai/docs/zh/models/image/nano-banana.md)，请在切换时检查格式值：Pro 接受 `jpg` 作为 JPEG 输出；原型号使用 `jpeg`。

| 功能 | 值 |
| - | - |
| 模型 ID | `nano-banana-pro` |
| 模式 | `text-to-image`, `image-to-image` |
| 提示词长度 | 1 至 5000 个字符 |
| 参考图片 | 最多支持 10 个 URL 用于 `image-to-image`。 |
| 纵横比 | `1:1`, `4:3`, `3:4`, `3:2`, `2:3`, `4:5`, `5:4`, `9:16`, `16:9`, `21:9` |
| 分辨率档位 | `1K`, `2K`, `4K` |
| 输出格式 | `png`, `jpg` |

## 接口与身份验证

API 基础地址：

```text theme={null}
https://api.apixo.ai/api/v1
```

| 方法 | 端点 | 用途 |
| - | - | - |
| `POST` | `/generateTask/nano-banana-pro` | 提交生成任务 |
| `GET` | `/statusTask/nano-banana-pro?taskId={taskId}` | 查询任务状态并获取结果 |

每个请求都必须携带 APIXO API 密钥：

```http theme={null}
Authorization: Bearer YOUR_API_KEY
```

提交任务时，还需要设置以下请求头：

```http theme={null}
Content-Type: application/json
```

## 异步请求示例

要生成上述目录照片，请将两个示例 URL 替换为产品照片和背景的公开链接。请求返回 `taskId`；最终图像 URL 来自 [状态响应](#poll-for-result)。对于无参考图像的提示，请使用 [文生图请求](#text-to-image)。

```bash theme={null}
curl -X POST "https://api.apixo.ai/api/v1/generateTask/nano-banana-pro" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "request_type": "async",
    "input": {
      "mode": "image-to-image",
      "image_urls": ["https://example.com/product.png", "https://example.com/background.jpg"],
      "prompt": "Place the product from the first photo on the counter in the second. Keep the label lettering and package color unchanged.",
      "aspect_ratio": "3:2",
      "resolution": "2K",
      "output_format": "png"
    }
  }'
```

成功响应：

```json theme={null}
{
  "code": 200,
  "message": "success",
  "data": {
    "taskId": "task_12345678"
  }
}
```

保存 `taskId`，后续轮询结果时需要用到它。

## 轮询结果

```bash theme={null}
curl -X GET "https://api.apixo.ai/api/v1/statusTask/nano-banana-pro?taskId=task_12345678" \
  -H "Authorization: Bearer YOUR_API_KEY"
```

任务处理中的响应示例：

```json theme={null}
{
  "code": 200,
  "message": "success",
  "data": {
    "taskId": "task_12345678",
    "state": "processing",
    "createTime": 1767965610929
  }
}
```

成功响应：

```json theme={null}
{
  "code": 200,
  "message": "success",
  "data": {
    "taskId": "task_12345678",
    "state": "success",
    "resultJson": "{\"resultUrls\":[\"https://file.apixo.ai/xxx.png\"]}",
    "createTime": 1767965610929,
    "completeTime": 1767965652317,
    "costTime": 41388
  }
}
```

任务失败时的响应示例：

```json theme={null}
{
  "code": 200,
  "message": "success",
  "data": {
    "taskId": "task_12345678",
    "state": "failed",
    "failCode": "CONTENT_VIOLATION",
    "failMsg": "Content does not meet safety guidelines",
    "createTime": 1767965610929,
    "completeTime": 1767965620132
  }
}
```

等 `state` 变为 `success` 后，再解析 `resultJson`：

```javascript theme={null}
const payload = JSON.parse(data.resultJson);
const imageUrls = payload.resultUrls;
```

## 请求体

### 文生图

```json theme={null}
{
  "request_type": "async",
  "input": {
    "mode": "text-to-image",
    "prompt": "a fox in watercolor style, crisp details",
    "aspect_ratio": "16:9",
    "resolution": "2K",
    "output_format": "png"
  }
}
```

### 图生图

```json theme={null}
{
  "request_type": "async",
  "input": {
    "mode": "image-to-image",
    "prompt": "combine these references into a futuristic cityscape",
    "image_urls": [
      "https://example.com/ref1.png",
      "https://example.com/ref2.jpg"
    ],
    "aspect_ratio": "16:9",
    "resolution": "4K",
    "output_format": "jpg"
  }
}
```

## 参数

**request\_type** `string` *required* (default: async)

结果获取方式。选择 `async` 时，通过 `statusTask` 轮询结果；选择 `callback` 时，通过 Webhook 接收结果。

**callback\_url** `string`

当 `request_type` 为 `callback` 时必填。请提供公网可访问的 HTTPS 地址，用于接收任务的最终结果。详见 [Webhook](https://apixo.ai/docs/zh/api-reference/webhooks.md)。

**input** `object` *required*

Nano Banana Pro 的输入参数。

**属性**

**mode** `string` *required*

生成模式。可选值为 `text-to-image`、`image-to-image`。

**prompt** `string` *required*

描述所需图像或编辑的文本提示。支持 1-5000 个字符，且修剪空格后不能为空。

**image\_urls** `string[]`

参考图像 URL。`image-to-image` 类型必需。最多支持 10 个 URL；每个 URL 必须是非空字符串。请使用公开的直接 JPG、PNG 或 WebP 链接。若与 `text-to-image` 一起发送，URL 将被验证但不会作为生成参考。

**aspect\_ratio** `string` *required*

输出画面的宽高比。可选值为 `1:1`、`4:3`、`3:4`、`3:2`、`2:3`、`4:5`、`5:4`、`9:16`、`16:9`、`21:9`。

**resolution** `string` *required*

Output分辨率层级。支持的值：`1K`、`2K`、`4K`。值区分大小写。

**output\_format** `string` (default: png)

输出图像格式。支持的值：`png`、`jpg`。默认值为 `png`。

## 响应格式

### 提交任务时的响应

任务受理后，`POST /generateTask/nano-banana-pro` 会返回任务 ID：

**code** `integer`

API 状态码。`200` 表示任务已受理。

**message** `string`

状态说明。

**data.taskId** `string`

任务的唯一 ID，用于查询任务状态。

### 状态响应字段

**taskId** `string`

任务的唯一标识符。

**state** `string`

当前任务状态，可能的值为 `pending`、`processing`、`success`、`failed`。

**resultJson** `string`

包含生成图片 URL 的 JSON 字符串。当 `state` 为 `success` 时返回。

**failCode** `string`

供程序处理的错误码，仅在 `state` 为 `failed` 时返回。

**failMsg** `string`

失败原因说明，仅在 `state` 为 `failed` 时返回。

**createTime** `integer`

任务创建时的 Unix 时间戳，单位为毫秒。

**completeTime** `integer`

任务完成时的 Unix 时间戳，单位为毫秒。任务完成后返回。

**costTime** `integer`

处理持续时间（以毫秒为单位）。当计时数据可用时返回。

## Webhook 回调模式

如果希望服务端自动收到最终结果，可以使用回调模式，无需轮询。

```bash theme={null}
curl -X POST "https://api.apixo.ai/api/v1/generateTask/nano-banana-pro" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "request_type": "callback",
    "callback_url": "https://your-server.com/webhooks/apixo",
    "input": {
      "mode": "image-to-image",
      "prompt": "create a polished advertising image while preserving the product shape",
      "image_urls": [
        "https://example.com/product.png"
      ],
      "aspect_ratio": "1:1",
      "resolution": "4K",
      "output_format": "png"
    }
  }'
```

Webhook 接收要求和重试规则见 [Webhook 文档](https://apixo.ai/docs/zh/api-reference/webhooks.md)。

## 计费

新提交的非 LLM 请求按 **1 积分 = `$0.001`** 计费。先按用量和附加项目计算总额，再应用账号折扣，最后将请求总额向上取整到整数积分。如果约定了固定单价，则按该单价的原始精度计算，不再使用标准价或另行打折；最终积分仍向上取整。详见[积分换算与取整](https://apixo.ai/docs/zh/pricing.md#credit-conversion-and-rounding)。

Nano Banana Pro 按生成的图像计费。所选的 `resolution` 决定单价。

| 分辨率 | APIXO 价格 | 市价 |
| - | - | - |
| `1K` / `2K` | `$0.08 / image` | `$0.15 / image` |
| `4K` | `$0.14 / image` | `$0.30 / image` |

最新的美元费率见 [API 价目表](https://apixo.ai/pricing/api)。

## 延迟与轮询

实际延迟可能因提示复杂性、参考图像可用性、提供者路由和当前队列负载而变化。

| 分辨率 | 通常生成耗时 | 建议首次查询时间 | 轮询间隔 |
| - | - | - | - |
| `1K` | 20s-30s | 任务创建 20 秒后 | 3s |
| `2K` | 30s-45s | 任务创建 20 秒后 | 3s |
| `4K` | 45s-60s | 任务创建 20 秒后 | 3s-5s |

> [!TIP]
>
> 对于高并发的生产工作负载，请使用回调模式以避免频繁轮询。结果URL有效期为15天；请及时下载并存储重要输出。

请求频率和并发上限因账号、API 密钥和路由而异。收到 `429` 时，请降低请求频率，逐步延长重试间隔。账号级限制见[系统 API](https://apixo.ai/docs/zh/api-reference/system.md)。

## 错误与排查

### HTTP 错误

| 代码 | 含义 | 处理方式 |
| - | - | - |
| `400` | 请求体、模式、参数、余额或图像URL格式无效。 | 在重试前修复请求 |
| `401` | 缺少 API 密钥，或密钥无效 | 检查 `Authorization` 请求头 |
| `402` | 余额或配额不足 | 充值或更换账号或API密钥 |
| `403` | 密钥或路由无权访问该模型 | 检查权限和路由策略 |
| `429` | 已达到速率或并发限制 | 按指数退避策略重试 |
| `500` | 服务器错误 | 逐步延长间隔后重试 |
| `502` | 服务错误 | 逐步延长间隔后重试 |
| `504` | 服务超时 | 重试；耗时较长的任务可改用回调模式 |

### 任务失败错误码

| 错误码 | 含义 | 处理方式 |
| - | - | - |
| `CONTENT_VIOLATION` | 提示或参考图像未通过安全检查 | 更改提示或输入图像 |
| `INVALID_IMAGE_URL` | 无法获取或解码参考图像 URL | 使用公开的直接图像 URL |
| `INVALID_PARAMETER` | 模型参数不受支持或格式错误 | 检查 `mode`、`prompt`、`aspect_ratio`、`resolution`、`image_urls` 和 `output_format`。 |
| `INSUFFICIENT_BALANCE` | 该账户没有足够的余额来执行任务 | 重试前需添加余额 |
| `UPSTREAM_ERROR` | 服务无法完成任务 | 使用退避重试或尝试其他路径 |
| `TIMEOUT` | 生成任务超时 | 重试、降低输入复杂度或使用回调模式 |

### 参数排查

| 问题表现 | 可能的原因 | 解决办法 |
| - | - | - |
| `Invalid mode type` | `input.mode` 缺失或不受支持 | 使用`text-to-image`或`image-to-image` |
| `aspect_ratio` 验证错误 | 该值缺失或不是支持的比率之一 | 发送精确支持的比率，例如 `16:9` |
| `resolution` 验证错误 | 该值缺失、小写或不受支持 | 准确发送 `1K`、`2K` 或 `4K` |
| `output_format` 验证错误 | 格式不受支持或格式错误 | 使用 `png` 或 `jpg` |
| 图生图任务失败 | `image_urls` 为空、无法访问、太大或不是直接图像 URL | 使用 1-10 个公共直接图像 URL |

完整列表见[错误码](https://apixo.ai/docs/zh/api-reference/errors.md)。

## MCP 集成

[完整模型 Schema](https://apixo.ai/docs/models/schemas/image/nano-banana-pro.json) 中的 `mcp.result` 指定了结果的解析方式，`mcp.attachments` 列出支持绑定文件的字段。这些元数据供客户端集成使用，无需作为生成参数提交。附件字段为 `image_urls`。请保留用户指定的文件顺序。API 负责校验模型参数。

## 相关链接

* [生成 API 概览](https://apixo.ai/docs/zh/models.md)
* [图像模型](https://apixo.ai/docs/zh/models/image)
* [提交生成任务](https://apixo.ai/docs/zh/api-reference/generate-task.md)
* [查询任务状态](https://apixo.ai/docs/zh/api-reference/status-task.md)
* [Webhook](https://apixo.ai/docs/zh/api-reference/webhooks.md)
* [错误码](https://apixo.ai/docs/zh/api-reference/errors.md)
* [参数规范](https://apixo.ai/docs/zh/api-reference/parameters.md)
* [路由策略](https://apixo.ai/docs/zh/concepts/routing-strategies.md)
* [在 APIXO Playground 尝试 Nano Banana Pro](https://apixo.ai/models/nano-banana-pro)
* [API定价](https://apixo.ai/pricing/api)


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