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

# GPT Image 图片生成与编辑

> GPT Image 2.0 / 2.5 / 2.6 文生图与图片编辑：推荐的异步接口（创建任务 → 查询 → 下载），以及给 OpenAI 标准工具用的同步接口

> [!NOTE]
>
> **给 AI 助手的要点**
>
> * **推荐异步**：`POST https://1788.love/v1/images/generations/async`（文生图）或 `POST https://1788.love/v1/images/edits/async`（编辑）→ 返回 `{ "id": "task_...", "status": "queued" }`；再 `GET https://1788.love/v1/images/tasks/{id}` 轮询，`status` 变成 `completed` 后取 `data[0].url`。人多、生成慢时异步不会因为连接超时而丢结果。
> * 同步接口 `POST /v1/images/generations`、`POST /v1/images/edits` 给必须使用 OpenAI 标准接口的工具（SDK、第三方客户端）用，等待时间长，会受网络超时影响。线路 5、8 没有同步接口；**线路 3 只有同步接口**，请把 HTTP 超时设到 2 分钟以上。
> * 请求字段两种接口一样：`model`、`prompt`、`size`、`n`（固定 1）、`response_format`（`url`）。模型名只带线路（`route3`），**不带清晰度**：清晰度（1K / 2K / 4K）由 `size` 决定，`size` 必须是尺寸表里的值，否则返回 400（错误信息会列出三档的合法尺寸）。旧写法 `gpt-image-2-route3-2k` 这种带档位的名字继续可用，但此时 `size` 必须属于该档位。
> * **参考图怎么传取决于线路**：线路 4 和线路 1、2、6 用 `multipart/form-data` 的 `image` 文件字段；线路 3、5、7、8 用 JSON 的 `image_urls`（公网 HTTPS 地址，先用[上传素材](https://docs.1788.love/api-reference/upload-image.md)换 URL；**线路 3 还支持直接传 `data:image/png;base64,...` 数据 URL**，大图建议直接用 Base64 避免跨国拉取超时）。
> * 一次请求一张图；要多张就并发提交多个任务。
> * **线路 5 提示**：提示词或参考图连续触发内容安全审核会导致线路 Key 被上游吊销。收到 `content_policy_violation` 时请修改内容，**不要原样重试**。

> [!WARNING]
>
> **内容合规红线**：严禁使用任何生图线路生成**色情、露点、低俗、反动政治及违法违规**内容。一经系统或人工核查发现，立即永久封停账号及 API Key 且不予退款！

## 模型和线路

| 线路 | 模型名 | 版本 | 异步 | 同步 | 参考图 | 尺寸表 |
| - | - | - | - | - | - | - |
| 3 | `gpt-image-2-route3` `gpt-image-2.5-route3-flare` / `gpt-image-2.5-route3-sunburst` `gpt-image-2.6-route3-flare` / `gpt-image-2.6-route3-sunburst` | 2.0 / 2.5 / 2.6 | ✗ | ✓ | JSON `image_urls`（HTTPS 或 Base64 data URL），最多 9 张 | 表 B |
| 4 | `gpt-image-2-route4` `gpt-image-2.5-route4-flare` `gpt-image-2.5-route4-sunburst`（2.5 精绘只有 1K） | 2.0 / 2.5 | ✓ | ✓ | multipart 文件 `image`，最多 10 张 | 表 A |
| 5 | `gpt-image-2-route5` `gpt-image-2.5-route5-flare` / `gpt-image-2.5-route5-sunburst` | 2.0 / 2.5 | ✓ | ✗ | JSON `image_urls`，最多 10 张 | 表 B |
| 7 | `gpt-image-2-route7` `gpt-image-2.5-route7-flare` / `gpt-image-2.5-route7-sunburst` `gpt-image-2.5-route7-flare-auto` / `gpt-image-2.5-route7-sunburst-auto` `gpt-image-2.5-route7-flare-eco` / `gpt-image-2.5-route7-sunburst-eco`（原生版只有 4K） | 2.0 / 2.5 | ✓ | ✓ | JSON `image_urls`，最多 10 张 | 表 B |
| 8 | `gpt-image-2-route8` | 2.0 | ✓ | ✗ | JSON `image_urls`，最多 10 张 | 表 A |
| 6（推荐） | `gpt-image-2-route6` `gpt-image-2.5-route6-flare` / `gpt-image-2.5-route6-sunburst`（2.5 只有 1K、2K） | 2.0 / 2.5 | ✗ | ✓ | multipart 文件 `image`，最多 10 张 | 表 A |
| 1 | `gpt-image-2-route1` `gpt-image-2.5-route1-flare` / `gpt-image-2.5-route1-sunburst` `gpt-image-2.6-route1-flare` / `gpt-image-2.6-route1-sunburst` | 2.0 / 2.5 / 2.6 | ✗ | ✓ | multipart 文件 `image`，最多 10 张 | 表 A |
| 2 | `gpt-image-2-route2` `gpt-image-2.5-route2-flare` / `gpt-image-2.5-route2-sunburst` `gpt-image-2.6-route2-flare` / `gpt-image-2.6-route2-sunburst` | 2.0 / 2.5 / 2.6 | ✗ | ✓ | multipart 文件 `image`，最多 10 张 | 表 A |

* **线路 1、2、3、6 只提供同步接口**（线路 3 上游改为同步出图，一般 20～40 秒返回；对线路 3 调用异步入口会返回 400）。

* 2.5 的 `flare` 是极速模式（速度优先，日常和批量出图），`sunburst` 是精绘模式（质量优先，精细生成和编辑）；线路 7 的 `auto` 是高清重绘（适合精修），`eco` 是原生版（只有 4K）。

* **2.6（线路 1、2、3）**：`flare` / `sunburst` 的含义和 2.5 相同。2.6 另外支持 **GIF 动图**和 **SVG 矢量图**，用 `output_format` 指定，见下面的“GIF 与 SVG（仅 2.6）”。

* 各线路能力相同，价格和速度略有差别，一条繁忙时可以换另一条。价格见[价目表](https://1788.love/pricing)，按次计费，每次请求一张图。

## 尺寸表

`size` 填像素值，**所在的档位就是计费档位**（1K / 2K / 4K），不用在模型名里写。**表 A 和表 B 只有 2K 档不同。**

表 A（线路 1、2、4、6、8）：

| 比例 | 1K | 2K | 4K |
| - | - | - | - |
| 1:1 | `1024x1024` | `2048x2048` | `2880x2880` |
| 3:2 | `1536x1024` | `2048x1365` | `3504x2336` |
| 2:3 | `1024x1536` | `1365x2048` | `2336x3504` |
| 16:9 | `1536x864` | `2048x1152` | `3840x2160` |
| 9:16 | `1024x1824` | `1152x2048` | `2160x3840` |
| 4:3 | `1536x1152` | `2048x1536` | `3264x2448` |
| 3:4 | `1152x1536` | `1536x2048` | `2448x3264` |

表 B（线路 3、5、7）：

| 比例 | 1K | 2K | 4K |
| - | - | - | - |
| 1:1 | `1024x1024` | `2048x2048` | `2880x2880` |
| 3:2 | `1536x1024` | `2560x1707` | `3504x2336` |
| 2:3 | `1024x1536` | `1707x2560` | `2336x3504` |
| 16:9 | `1536x864` | `2560x1440` | `3840x2160` |
| 9:16 | `1024x1824` | `1440x2560` | `2160x3840` |
| 4:3 | `1536x1152` | `2048x1536` | `3264x2448` |
| 3:4 | `1152x1536` | `1536x2048` | `2448x3264` |

不带档位的模型名会按 `size` 自动判断档位，`size` 不在任何一档的表里会返回 400。继续使用旧写法（例如 `gpt-image-2-route3-1k`）时，`size` 必须属于名字里的那一档，例如 `-1k` 配 `3840x2160` 会返回 400。

## 异步接口（推荐）

### 1. 创建任务

文生图：

```bash theme={null}
curl https://1788.love/v1/images/generations/async \
  -H "Authorization: Bearer YOUR_1788_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-image-2-route7",
    "prompt": "白色背景上的一双运动鞋，商业产品摄影，柔和阴影",
    "size": "2048x2048",
    "n": 1
  }'
```

编辑 / 参考图生图（线路 5、7、8，JSON 的 `image_urls`）：

```bash theme={null}
curl https://1788.love/v1/images/edits/async \
  -H "Authorization: Bearer YOUR_1788_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-image-2.5-route7-sunburst",
    "prompt": "把图1的模特换上图2的外套，保持人物姿势和背景不变",
    "size": "1440x2560",
    "n": 1,
    "image_urls": [
      "https://ruyi6.cn/r/EXAMPLE_A.png",
      "https://ruyi6.cn/r/EXAMPLE_B.png"
    ]
  }'
```

线路 4 的编辑用 multipart 文件：

```bash theme={null}
curl https://1788.love/v1/images/edits/async \
  -H "Authorization: Bearer YOUR_1788_API_KEY" \
  -F model=gpt-image-2.5-route4-flare \
  -F prompt="把图1的模特换上图2的外套" \
  -F size=1024x1536 \
  -F image=@model.png \
  -F image=@coat.png
```

创建成功（HTTP 202）：

```json theme={null}
{
  "id": "task_xxxxxxxx",
  "object": "image.task",
  "model": "gpt-image-2-route7",
  "status": "queued",
  "created_at": 1793500000
}
```

任务一旦创建就会计费，失败按规则退款。保存 `id`。

### 2. 查询任务

`GET https://1788.love/v1/images/tasks/{id}`，请求头同样带 API Key。建议每 3–5 秒查一次，生成通常需要 30 秒到 3 分钟。

| `status` | 含义 | 下一步 |
| - | - | - |
| `queued` | 已排队 | 继续查询 |
| `in_progress` | 正在生成 | 继续查询 |
| `completed` | 已完成 | 用 `data[0].url` 下载 |
| `failed` | 失败 | 看 `error`；失败任务会退款 |

完成：

```json theme={null}
{
  "id": "task_xxxxxxxx",
  "object": "image.task",
  "model": "gpt-image-2-route7",
  "status": "completed",
  "progress": "100",
  "created_at": 1793500000,
  "data": [{ "url": "https://1788.love/v1/tasks/task_xxxxxxxx/artifacts/image-1/content?access=...&expires=..." }]
}
```

失败：

```json theme={null}
{
  "id": "task_xxxxxxxx",
  "object": "image.task",
  "model": "gpt-image-2-route5",
  "status": "failed",
  "error": { "code": "content_policy_violation", "message": "the prompt or reference images were rejected by the content policy; change them before retrying" }
}
```

`error.code` 只有两种：`content_policy_violation`（提示词或参考图触发安全审核）和 `image_generation_failed`（其他原因）。

### 3. 下载图片

* 线路 4、7：`data[0].url` 是带时效签名的地址，可以直接下载，无需请求头。图片有时效，请尽快保存。
* 同步线路 1、2、3、6 返回的 `data[0].url` 是图床直链：下载时**不要**带 `Authorization` 请求头，部分图床带了会返回 403。线路 2、3 的图床还会拦截没有浏览器标识的请求（返回 403 `error code: 1010`），用 Python、脚本下载时请设置 `User-Agent`（例如 `curl/8.5.0` 或常见浏览器的值）。
* 线路 5：`data[0].url` 需要在请求头带 `Authorization: Bearer YOUR_1788_API_KEY` 才能下载；结果保留 24 小时。
* 线路 8：查询结果的字段略有不同：任务号字段叫 `task_id`（不是 `id`），生成中的 `status` 是 `processing`（不是 `in_progress`），完成后 `data[0].url` 为图片地址。按"`completed` 算完成、`failed` 算失败、其余继续查询"处理即可兼容所有线路。

```bash theme={null}
curl -L -o result.png "<data[0].url>"
```

### Python 完整流程

```python theme={null}
import time
import requests

BASE = "https://1788.love"
HEADERS = {"Authorization": "Bearer YOUR_1788_API_KEY"}

task = requests.post(f"{BASE}/v1/images/generations/async", headers=HEADERS, json={
    "model": "gpt-image-2-route7",
    "prompt": "一只橘猫坐在窗台上，午后阳光",
    "size": "1024x1024",
    "n": 1,
}).json()

while True:
    info = requests.get(f"{BASE}/v1/images/tasks/{task['id']}", headers=HEADERS).json()
    if info["status"] == "completed":
        break
    if info["status"] == "failed":
        raise RuntimeError(info["error"])
    time.sleep(5)

image = requests.get(info["data"][0]["url"], headers=HEADERS)
open("result.png", "wb").write(image.content)
```

## 同步接口（给只认 OpenAI 标准接口的工具）

`POST /v1/images/generations`（JSON）和 `POST /v1/images/edits`（线路 1、2、4、6 用 multipart 文件，线路 3、7 用 JSON 的 `image_urls`），请求字段和异步一样，成功后直接返回：

```json theme={null}
{ "created": 1793500000, "data": [{ "url": "https://...png" }] }
```

```bash theme={null}
curl https://1788.love/v1/images/generations \
  -H "Authorization: Bearer YOUR_1788_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-image-2-route6",
    "prompt": "白色背景上的一双运动鞋，商业产品摄影，柔和阴影",
    "size": "2048x2048",
    "n": 1,
    "response_format": "url"
  }'
```

线路 1、2、4、6 的编辑（multipart 文件）：

```bash theme={null}
curl https://1788.love/v1/images/edits \
  -H "Authorization: Bearer YOUR_1788_API_KEY" \
  -F model=gpt-image-2.5-route6-sunburst \
  -F prompt="把图1的模特换上图2的外套，保持人物姿势和背景不变" \
  -F size=1024x1536 \
  -F n=1 \
  -F response_format=url \
  -F image=@model.png \
  -F image=@coat.png
```

图片支持 PNG、JPEG、WebP，单张建议不超过 10 MB。线路 3、7 的同步编辑用 JSON `image_urls`；对线路 3、7 发 multipart 文件、对线路 4 在 JSON 里带 `image_urls` 都会返回 400。其中**线路 3 的 `image_urls` 除了公网 HTTPS 链接，还支持直接传入 Base64 数据 URL（`data:image/png;base64,...`，支持 PNG / JPEG / WebP / GIF，单图编码后不超过 16 MB）**——如果参考图较大或放在国内域名导致上游拉取超时，推荐直接用 Base64 传入，或改用 `https://1788.love/v1/uploads/images-2` 上传后取香港地址。线路 3、4、7 的同步接口还可以填 `response_format: "b64_json"`。

### 同步接口的超时

* 同步请求会一直等到出图。线路 4、7 网关最多等 10 分钟，超过返回 `504 task_timeout`，此时图片可能仍在生成并会按完成情况结算，**不要立刻重复提交**。
* 线路 3 上游超过 85 秒未出图时，网关直接返回失败并退款，可以放心重试。
* 线路 1、2、6 的上限是网关的 15 分钟连接超时（实际取决于上游出图速度）。
* 客户端连接中途断开时，任务仍在后台完成并结算，但同步接口无法再取回结果。**所以建议把 HTTP 超时设到 15 分钟以上，或者直接用异步接口。**

## 常见错误

| 现象 | 原因 | 处理 |
| - | - | - |
| 400 `size ... is not a valid size ...` / `size must be one of ...` | `size` 不在尺寸表里，或没填 `size`；用旧写法时 `size` 不属于名字里的档位 | 按尺寸表选一个值；去掉模型名里的 `-1k` / `-2k` / `-4k` |
| 400 `unsupported parameter: ...` | 线路 3、4、7 收到了不支持的参数 | 去掉该参数 |
| 400 `n must be 1` | 一次请求只能一张图 | `n` 填 1，要多张就并发提交 |
| 400 `image_urls is required for edits` | 线路 3、7 的编辑请求没带 `image_urls` | 加上公网 HTTPS 图片地址 |
| 400 `image_urls must contain public HTTPS URLs...` | 地址不是 `https://`、是内网地址、非合法图片 Base64 data URL 或数量超限 | 先[上传素材](https://docs.1788.love/api-reference/upload-image.md)用返回的 URL，或（线路 3）传入合法 `data:image/png;base64,...` |
| 400 `... take reference images as ...` | 对线路 3、7 发了 multipart 文件 | 改用 JSON 的 `image_urls` |
| 400 `... takes reference images as uploaded files` | 对线路 4 在 JSON 里带了 `image_urls` | 改用 multipart 上传文件 |
| 查询到 `failed`，`error.code` 为 `content_policy_violation` | 提示词或参考图触发安全审核 | 修改内容后再提交，**不要原样重试**（线路 5 反复触发会导致 Key 被吊销） |
| 同步请求 504 `task_timeout` | 上游生成超过 10 分钟 | 稍后检查账户消耗，不要立刻重发；以后改用异步接口 |
| 429 / 5xx | 线路繁忙 | 稍后重试，或换另一条线路 |

## GIF 与 SVG（仅 2.6）

线路 1、2、3 的 `gpt-image-2.6-*` 模型支持动图和矢量图，请求和普通出图一样走 `POST /v1/images/generations`，一张的价格和一张静态图相同，与帧数、尺寸无关。

```bash theme={null}
curl https://1788.love/v1/images/generations   -H "Authorization: Bearer $API_KEY"   -H "Content-Type: application/json"   -d '{
    "model": "gpt-image-2.6-route3-flare",
    "prompt": "a paper airplane looping across a blue sky, flat illustration, seamless loop",
    "output_format": "gif",
    "frame_count": 6,
    "frame_duration_ms": 200,
    "size": "512x512"
  }'
```

| 字段 | 说明 |
| - | - |
| `output_format` | `gif` 或 `svg`；不传就是普通 PNG。2.0 / 2.5 的模型不支持，返回 400 |
| `frame_count` | 仅 GIF，帧数，2 到 16 |
| `frame_duration_ms` | 仅 GIF，每帧时长（毫秒），20 到 2000 |
| `size` | GIF 的 `size` 是**单帧像素**，如 `512x512`，不能写 `1:1` 这样的比例，也可以省略；SVG 不需要 `size` |

* GIF、SVG 不受 1K / 2K / 4K 尺寸表限制，不带档位的模型名会按 1K 处理；成品 GIF 的实际宽高可能和请求略有出入（例如 512 变成 508）。
* 线路 3 返回图片链接 `url`，线路 2 返回 `b64_json`，线路 1 按上游节点返回 `url` 或 `b64_json`；GIF 用时通常 30 秒到 2 分钟，SVG 约 10 到 30 秒。
* 线路 2 的 4K 档位不支持 SVG。


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