# Gemini 图像生成
> 文生图与参考图编辑
> 参考图最多 14 张，单张 30MB
> 支持 1K / 2K / 4K 三档输出
`POST /v1/images/generations`
## 认证
- `Authorization` (string / 必填) — 所有接口均使用 Bearer Token 进行认证。 获取 API Key：[访问控制台](https://api.oairoute.com/keys) 创建。 请求时在请求头中添加： ```http Authorization: Bearer YOUR_OAIRoute_KEY ```
## 请求结构
请求体是平铺的 JSON，创作字段与输出字段都在顶层，没有 `content` 数组包装。
## 支持的场景
| 场景 | 字段组合 |
|---|---|
| 文生图 | `prompt` |
| 单图编辑 | `prompt` + `image`（1 张） |
| 多图参考 | `prompt` + `image`（2 到 14 张） |
带 `image` 即进入图生图，不需要额外参数切换。
## 请求参数
> **Note:** 
> 提交成功只返回任务 ID，不含图片本身。拿结果用 `task_id` 轮询[获取任务状态](../tasks/status.html)，图片地址在 `result.images[0].url`，该地址会过期，请及时转存。
- `model` (string / 必填) — 取值 `gemini-3-pro-image-preview` 或 `gemini-3-pro-image-preview-official`。 `nano-banana-pro` 与 `nano-banana-pro-ext` 是等价别名。
- `prompt` (string / 必填) — 画面描述。
- `size` (string / 可选) — 宽高比，取值 `auto`、`1:1`、`2:3`、`3:2`、`3:4`、`4:3`、`4:5`、`5:4`、`9:16`、`16:9`、`21:9`。 `auto` 在文生图下回落为 `1:1` 或 `16:9`，图生图下跟随上游返回比例。建议显式指定。
- `resolution` (string / 可选) — 取值 `1K`（默认）、`2K`、`4K`。
- `n` (integer / 可选) — 只能是 `1`。必须传数字。
- `image` (string | string[] / 可选) — 参考图，最多 14 张。公网地址或完整 Base64 Data URI（前缀 `data:image/jpeg;base64,` 等不能省）。 单张不超过 30MB，格式 jpeg、jpg、png、webp。
- `official_fallback` (boolean / 可选) — 允许回落到官方通道，默认 `false`。不能与官方模型同时使用。
- `nsfw_check` (boolean / 可选) — 为 `true` 时先做内容审查，默认 `false`。
## 输出尺寸参考
| 比例 | 1K | 2K | 4K |
|---|---|---|---|
| 1:1 | 1024×1024 | 2048×2048 | 4096×4096 |
| 16:9 | 1376×768 | 2752×1536 | 5504×3072 |
| 9:16 | 768×1376 | 1536×2752 | 3072×5504 |
| 21:9 | 1584×672 | 3168×1344 | 6336×2688 |
以返回文件的实际尺寸为准。
## 响应
提交成功返回受理结构：
```json
{
  "code": 200,
  "data": [
    {
      "status": "submitted",
      "task_id": "task_01K8SGYNNNVBQTXNR4MM964S7K"
    }
  ]
}
```
- `code` (integer / 总是返回) — 状态码，`200` 表示任务已受理。
- `data` (array / 总是返回) — 本次提交的任务列表。
- `data[].status` (string / 总是返回) — 受理状态，提交成功时为 `submitted`。
- `data[].task_id` (string / 总是返回) — 任务 ID，用它轮询结果。
完成态返回：
```json
{
  "code": 200,
  "data": {
    "id": "task_01K8SGYNNNVBQTXNR4MM964S7K",
    "status": "completed",
    "progress": 100,
    "result": {
      "images": [
        { "url": ["https://cdn.oairoute.com/f/image/task_01K8_0.png"], "expires_at": 1763174708 }
      ]
    },
    "created": 1763088289,
    "completed": 1763088302
  }
}
```
## 错误码
| HTTP | 含义 |
|---|---|
| 400 | 参数错误，type 为 invalid_request_error |
| 401 | Token 缺失或无效，type 为 authentication_error |
| 402 | 余额不足，type 为 payment_required |
| 429 | 触发限流 |
更多状态码与重试建议见[错误码与限流](../../support/errors.html)，常见报错的排查步骤见[常见问题](../../support/faq.html)。
## 支持的模型列表
| 模型 ID | 定位 |
|---|---|
| `gemini-3-pro-image-preview` | 当前主力，最高 4K |
| `gemini-3-pro-image-preview-official` | 官方通道版本，输出一致 |
| `nano-banana-pro` | `gemini-3-pro-image-preview-official` 的别名 |
| `nano-banana-pro-ext` | `gemini-3-pro-image-preview` 的别名 |
别名与主名行为完全一致，可以互换。
> **Note:** 完整模型目录（含价格、分辨率上限）可读取 `GET https://api.oairoute.com/api/pricing`。
## 使用示例
**文生图{Text to image}::cURL**
```
curl --request POST \
  --url 'https://api.oairoute.com/v1/images/generations' \
  --header 'Authorization: Bearer YOUR_OAIRoute_KEY' \
  --header 'Content-Type: application/json' \
  --data '{
  "model": "gemini-3-pro-image-preview",
  "prompt": "月光下的竹林小径，薄雾，冷色调",
  "size": "1:1",
  "resolution": "2K"
}'
```
**文生图{Text to image}::Python**
```
import requests
url = "https://api.oairoute.com/v1/images/generations"
headers = {
    "Authorization": "Bearer YOUR_OAIRoute_KEY",
    "Content-Type": "application/json",
}
payload = {
  "model": "gemini-3-pro-image-preview",
  "prompt": "月光下的竹林小径，薄雾，冷色调",
  "size": "1:1",
  "resolution": "2K"
}
res = requests.post(url, headers=headers, json=payload)
print(res.json())
```
**文生图{Text to image}::JavaScript**
```
const res = await fetch("https://api.oairoute.com/v1/images/generations", {
  method: "POST",
  headers: {
    Authorization: "Bearer YOUR_OAIRoute_KEY",
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
  "model": "gemini-3-pro-image-preview",
  "prompt": "月光下的竹林小径，薄雾，冷色调",
  "size": "1:1",
  "resolution": "2K"
}),
});
console.log(await res.json());
```
**200 文生图{Text to image}**
```
{
  "code": 200,
  "data": [
    {
      "status": "submitted",
      "task_id": "task_01K8SGYNNNVBQTXNR4MM964S7K"
    }
  ]
}
```
**参考图编辑{Reference edit}::cURL**
```
curl --request POST \
  --url 'https://api.oairoute.com/v1/images/generations' \
  --header 'Authorization: Bearer YOUR_OAIRoute_KEY' \
  --header 'Content-Type: application/json' \
  --data '{
  "model": "gemini-3-pro-image-preview",
  "prompt": "保留人物，把背景换成海边黄昏",
  "image": [
    "https://example.com/person.jpg"
  ],
  "size": "3:4"
}'
```
**参考图编辑{Reference edit}::Python**
```
import requests
url = "https://api.oairoute.com/v1/images/generations"
headers = {
    "Authorization": "Bearer YOUR_OAIRoute_KEY",
    "Content-Type": "application/json",
}
payload = {
  "model": "gemini-3-pro-image-preview",
  "prompt": "保留人物，把背景换成海边黄昏",
  "image": [
    "https://example.com/person.jpg"
  ],
  "size": "3:4"
}
res = requests.post(url, headers=headers, json=payload)
print(res.json())
```
**参考图编辑{Reference edit}::JavaScript**
```
const res = await fetch("https://api.oairoute.com/v1/images/generations", {
  method: "POST",
  headers: {
    Authorization: "Bearer YOUR_OAIRoute_KEY",
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
  "model": "gemini-3-pro-image-preview",
  "prompt": "保留人物，把背景换成海边黄昏",
  "image": [
    "https://example.com/person.jpg"
  ],
  "size": "3:4"
}),
});
console.log(await res.json());
```
**200 参考图编辑{Reference edit}**
```
{
  "code": 200,
  "data": [
    {
      "status": "submitted",
      "task_id": "task_01K8SGYNNNVBQTXNR4MM964S7K"
    }
  ]
}
```
**多图参考{Multi reference}::cURL**
```
curl --request POST \
  --url 'https://api.oairoute.com/v1/images/generations' \
  --header 'Authorization: Bearer YOUR_OAIRoute_KEY' \
  --header 'Content-Type: application/json' \
  --data '{
  "model": "gemini-3-pro-image-preview",
  "prompt": "把图1 的人物放进图2 的场景，保持光照一致",
  "image": [
    "https://example.com/a.jpg",
    "https://example.com/b.jpg"
  ]
}'
```
**多图参考{Multi reference}::Python**
```
import requests
url = "https://api.oairoute.com/v1/images/generations"
headers = {
    "Authorization": "Bearer YOUR_OAIRoute_KEY",
    "Content-Type": "application/json",
}
payload = {
  "model": "gemini-3-pro-image-preview",
  "prompt": "把图1 的人物放进图2 的场景，保持光照一致",
  "image": [
    "https://example.com/a.jpg",
    "https://example.com/b.jpg"
  ]
}
res = requests.post(url, headers=headers, json=payload)
print(res.json())
```
**多图参考{Multi reference}::JavaScript**
```
const res = await fetch("https://api.oairoute.com/v1/images/generations", {
  method: "POST",
  headers: {
    Authorization: "Bearer YOUR_OAIRoute_KEY",
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
  "model": "gemini-3-pro-image-preview",
  "prompt": "把图1 的人物放进图2 的场景，保持光照一致",
  "image": [
    "https://example.com/a.jpg",
    "https://example.com/b.jpg"
  ]
}),
});
console.log(await res.json());
```
**200 多图参考{Multi reference}**
```
{
  "code": 200,
  "data": [
    {
      "status": "submitted",
      "task_id": "task_01K8SGYNNNVBQTXNR4MM964S7K"
    }
  ]
}
```
**4K 输出{4K output}::cURL**
```
curl --request POST \
  --url 'https://api.oairoute.com/v1/images/generations' \
  --header 'Authorization: Bearer YOUR_OAIRoute_KEY' \
  --header 'Content-Type: application/json' \
  --data '{
  "model": "gemini-3-pro-image-preview",
  "prompt": "雪山日出，云海翻涌",
  "size": "16:9",
  "resolution": "4K"
}'
```
**4K 输出{4K output}::Python**
```
import requests
url = "https://api.oairoute.com/v1/images/generations"
headers = {
    "Authorization": "Bearer YOUR_OAIRoute_KEY",
    "Content-Type": "application/json",
}
payload = {
  "model": "gemini-3-pro-image-preview",
  "prompt": "雪山日出，云海翻涌",
  "size": "16:9",
  "resolution": "4K"
}
res = requests.post(url, headers=headers, json=payload)
print(res.json())
```
**4K 输出{4K output}::JavaScript**
```
const res = await fetch("https://api.oairoute.com/v1/images/generations", {
  method: "POST",
  headers: {
    Authorization: "Bearer YOUR_OAIRoute_KEY",
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
  "model": "gemini-3-pro-image-preview",
  "prompt": "雪山日出，云海翻涌",
  "size": "16:9",
  "resolution": "4K"
}),
});
console.log(await res.json());
```
**200 4K 输出{4K output}**
```
{
  "code": 200,
  "data": [
    {
      "status": "submitted",
      "task_id": "task_01K8SGYNNNVBQTXNR4MM964S7K"
    }
  ]
}
```
