GPT 图像
- 文生图、参考图编辑、蒙版重绘
- 参考图最多 16 张,一次生成最多 4 张
- 画质分 low / medium / high / xhigh / max 五档
认证
All endpoints authenticate with a Bearer token.
Get an API key: open the console and create one.
Add it to the request header:
Authorization: Bearer YOUR_OAIRoute_KEY请求结构
请求体是平铺的 JSON,创作字段与输出字段都在顶层,没有 content 数组包装。
The body is flat JSON: creative fields and output fields sit at the top level, with no content array wrapper.
支持的场景
| 场景 | 字段组合 |
|---|---|
| 文生图 | prompt |
| 单图编辑 | prompt + image(1 张) |
| 多图参考 | prompt + image(2 到 16 张) |
| 蒙版重绘 | prompt + image + mask_url |
| 固定画布 | size 写精确像素 |
传入 image 后自动进入编辑模式,不需要额外参数切换。mask_url 单独传无效。
| Scenario | Field combination |
|---|---|
| Text to image | prompt |
| Single-image edit | prompt + image (1 image) |
| Multi-image reference | prompt + image (2 to 16 images) |
| Masked repaint | prompt + image + mask_url |
| Fixed canvas | size written as exact pixels |
Passing image enters edit mode automatically; no extra parameter is needed. mask_url alone has no effect.
请求参数
提交后同步返回图片本身,不返回任务 ID。图片在 data[].b64_json,是 Base64 字符串,客户端解码后落盘。需要动图或矢量输出见 GPT Image 2.6。
取值 gpt-image-2.5-flare 或 gpt-image-2.5-sunburst。
两者单价相同,flare 偏速度与批量,sunburst 偏编辑精度与多轮打磨。
画面描述,中英文均可。建议写清主体、场景、构图、风格、光线,以及哪些必须保留、哪些需要改动。
默认 auto。
可写宽高比 1:1、3:2、2:3、4:3、3:4、5:4、4:5、16:9、9:16、2:1、1:2、21:9、9:21、3:1、1:3,也可写精确像素如 1600x1200。
图生图时建议省略,由模型按输入图比例推算。
输出档位,取值 1k(默认)、2k、4k。
与比例形式的 size 配合决定像素;size 写精确像素时该字段失效。
画质档位,取值 low、medium、high、xhigh、max、auto,默认 auto。
auto 先按最高档预扣,完成后按实际 token 结算。
生成张数,取值 1 到 4,默认 1。必须传数字,不能传字符串。
参考图,最多 16 张公网地址。
传入即进入编辑模式:第一张是主体,其余作为场景、光线或风格参考。
蒙版,仅配合 image 使用,只作用于第一张参考图。
透明像素表示可重绘区域。像素尺寸必须与第一张参考图完全一致,而不是与输出尺寸一致。
取值 png(默认)、jpeg、webp。PNG 与 WebP 支持透明背景。
压缩比,取值 0 到 100,仅对 jpeg 与 webp 生效。
取值 transparent、opaque、auto。
transparent 与 jpeg 不能同时使用。
内容审核档位,取值 auto、low,默认 low。
A successful submission returns only the task ID, not the image itself. Poll Get task status with the task_id; the image URL is at result.images[0].url and expires, so copy it promptly.
gpt-image-2.5-flare or gpt-image-2.5-sunburst.
Both cost the same; flare favors speed and batch work, while sunburst favors edit precision and iterative refinement.
The scene description, in Chinese or English. Spell out the subject, setting, composition, style, lighting, and what must stay versus what must change.
Defaults to auto.
Accepts aspect ratios 1:1, 3:2, 2:3, 4:3, 3:4, 5:4, 4:5, 16:9, 9:16, 2:1, 1:2, 21:9, 9:21, 3:1, 1:3, or exact pixels such as 1600x1200.
For image-to-image, prefer omitting it and letting the model infer the input image's ratio.
Output tier: 1k (default), 2k, or 4k.
Combined with a ratio-form size it determines the pixels; when size is exact pixels, this field has no effect.
Quality tier: low, medium, high, xhigh, max, or auto; defaults to auto.
auto holds the highest tier up front and settles by actual tokens afterward.
Number of images, 1 to 4, default 1. Must be a number, not a string.
Reference images, up to 16 public URLs.
Passing these enters edit mode: the first is the subject, and the rest serve as scene, lighting, or style references.
A mask, used only with image, affecting only the first reference image.
Transparent pixels mark the repaintable area. Its pixel dimensions must match the first reference image exactly — not the output size.
png (default), jpeg, or webp. PNG and WebP support transparent backgrounds.
Compression level, 0 to 100, applies only to jpeg and webp.
transparent, opaque, or auto.
transparent can't be combined with jpeg.
Content moderation level: auto or low; defaults to low.
尺寸约束
精确像素时:宽高都必须能被 16 整除,单边不超过 3840,长短边比例不超过 3:1,总像素在 655360 到 8294400 之间。
比例形式与 resolution 组合出像素,例如 1:1 在 1k / 2k / 4k 下分别是 1024×1024、2048×2048、2880×2880。
超过 2560×1440 的输出稳定性会下降,属于实验范围。
For exact pixels: both sides must be divisible by 16, neither side over 3840, the long-to-short ratio no more than 3:1, and total pixels between 655360 and 8294400.
Ratio form combined with resolution yields pixels — 1:1 gives 1024×1024, 2048×2048, and 2880×2880 at 1k, 2k, and 4k respectively.
Output above 2560×1440 is less stable and considered experimental.
响应
同步返回,与 OpenAI Images API 一致。返回体里只有 b64_json 与 generation_id,没有图片 URL;请求会阻塞到图片生成完成,没有任务 ID,也不需要轮询。
字段说明
created(integer) — 生成完成时间,Unix 秒。data(array) — 每项对应一张输出图。data[].b64_json(string) — Base64 图片数据,解码后即 PNG / JPEG / WebP 文件。本接口不返回图片 URL,必须自己解码落盘。data[].generation_id(string) — 本次生成的唯一标识,可用于日志关联与排障。size(string) — 实际输出尺寸,如1536x1024。output_format(string) — 实际输出格式。quality(string) — 实际使用的画质档位。background(string / 可选) —transparent或opaque。usage(object) — 计费用量,含input_tokens、output_tokens、total_tokens,以及图片 / 文本分项。
生成是同步的,请求会阻塞到图片出完。普通尺寸通常几十秒,复杂提示词官方给出上限约 2 分钟,客户端超时建议设到 3 分钟以上。WebP 与 JPEG 比 PNG 快,对延迟敏感时优先选这两种。
Returned synchronously, in the OpenAI Images API shape. The body carries only b64_json and generation_id; there is no image URL, and the request blocks until generation finishes. No task ID, nothing to poll.
Fields
created(integer) — completion time, Unix seconds.data(array) — one entry per output image.data[].b64_json(string) — Base64 image data that decodes to a PNG / JPEG / WebP file. No URL is returned; decode and write the file yourself.data[].generation_id(string) — a unique id for this generation, useful for log correlation and debugging.size(string) — the actual output dimensions, e.g.1536x1024.output_format(string) — the format actually produced.quality(string) — the quality tier actually used.background(string / optional) —transparentoropaque.usage(object) — billing usage withinput_tokens,output_tokens,total_tokensand image/text breakdowns.
Generation is synchronous: the request blocks until the image is ready. Ordinary sizes take tens of seconds, and OpenAI caps complex prompts at about 2 minutes, so set client timeouts above 3 minutes. WebP and JPEG are faster than PNG; prefer them when latency matters.
错误码
| HTTP | 含义 |
|---|---|
| 400 | 参数错误,type 为 invalid_request_error |
| 401 | Token 缺失或无效,type 为 authentication_error |
| 402 | 余额不足,type 为 payment_required |
| 429 | 触发限流 |
| HTTP | Meaning |
|---|---|
| 400 | Invalid parameters, with type invalid_request_error |
| 401 | Token missing or invalid, with type authentication_error |
| 402 | Insufficient balance, with type payment_required |
| 429 | Rate limit hit |
For more status codes and retry guidance see Error codes and rate limits; for troubleshooting steps on common errors see the FAQ.
支持的模型
| 模型 ID | 定位 | GIF / SVG |
|---|---|---|
gpt-image-2.6-flare | 2.6 代,速度优先,适合批量与原型 | ✅ |
gpt-image-2.6-sunburst | 2.6 代,细节优先,适合成品图与多轮打磨 | ✅ |
gpt-image-2.5-flare | 速度优先,适合批量与原型 | — |
gpt-image-2.5-sunburst | 编辑精度优先,适合成品图与多轮打磨 | — |
gpt-image-2 | 上一代主力,不支持 xhigh 与 max 档 | — |
gpt-image-1.5 | 轻量,出图快 | — |
gpt-image-1-mini | 成本最低 | — |
xhigh 与 max 只有 2.5 及以后支持,传给 gpt-image-2 会返回 400,不会降档。gif 与 svg 只有 2.6 支持,参数细节见 GPT Image 2.6。
完整模型目录(含价格、分辨率上限)可读取 GET https://api.oairoute.com/api/pricing;也可用 GET /v1/models 筛 supported_endpoint_types 含 image-generation 的条目。
| Model ID | Positioning | GIF / SVG |
|---|---|---|
gpt-image-2.6-flare | 2.6 generation, speed first; batch work and prototyping | ✅ |
gpt-image-2.6-sunburst | 2.6 generation, detail first; finished images and iteration | ✅ |
gpt-image-2.5-flare | Speed first; batch work and prototyping | — |
gpt-image-2.5-sunburst | Edit precision first; finished images and iteration | — |
gpt-image-2 | Previous main model; no xhigh or max | — |
gpt-image-1.5 | Lightweight, fast output | — |
gpt-image-1-mini | Lowest cost | — |
xhigh and max exist from 2.5 onward; passing them to gpt-image-2 returns 400 rather than downgrading. gif and svg exist only on 2.6; see GPT Image 2.6 for the parameters.
The full catalog (prices, resolution limits) is available from GET https://api.oairoute.com/api/pricing, or filter GET /v1/models for entries whose supported_endpoint_types contain image-generation.