通过媒体任务接口接入 gpt-image-2.5-flare。 包含请求示例、参数、鉴权和结果处理。 图生图场景指南。
/v1/tasksMODELgpt-image-2.5-flare代码示例与响应
/v1/taskscurl "https://newrouters.com/v1/tasks" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $API_KEY" \
--data '{
"model": "gpt-image-2.5-flare",
"input": {
"quality": "medium",
"resolution": "1k",
"output_format": "jpeg",
"prompt": "Keep the subject and replace the background with a quiet garden",
"images": [
"https://example.com/reference.png"
]
}
}'const apiBaseUrl = "https://newrouters.com";
const apiKey = process.env.API_KEY;
if (!apiKey) throw new Error("Set API_KEY in your server environment");
const response = await fetch(apiBaseUrl + "/v1/tasks", {
method: "POST",
headers: {
"Content-Type": "application/json",
"Authorization": "Bearer " + apiKey
},
body: JSON.stringify({
"model": "gpt-image-2.5-flare",
"input": {
"quality": "medium",
"resolution": "2k",
"output_format": "jpeg",
"prompt": "Keep the subject and replace the background with a quiet garden",
"images": [
"https://example.com/reference.png"
],
"size": "auto"
}
})
});
const result = await response.json();
if (!response.ok) throw new Error(JSON.stringify(result));
console.log(result);import json
import os
from urllib.request import Request, urlopen
api_base_url = "https://newrouters.com"
api_key = os.environ["API_KEY"]
body = json.loads("{\"model\":\"gpt-image-2.5-flare\",\"input\":{\"quality\":\"medium\",\"resolution\":\"2k\",\"output_format\":\"jpeg\",\"prompt\":\"Keep the subject and replace the background with a quiet garden\",\"images\":[\"https://example.com/reference.png\"],\"size\":\"auto\"}}")
request = Request(
api_base_url + "/v1/tasks",
data=json.dumps(body).encode("utf-8"),
headers={
"Content-Type": "application/json",
"Authorization": "Bearer " + api_key
},
method="POST",
)
with urlopen(request) as response:
print(json.load(response))平台地址已填入,运行前设置 API_KEY 环境变量。示例不会自动发起请求。
202任务已受理
{
"id": "TASK_ID",
"status": "pending",
"model": "gpt-image-2.5-flare",
"result": null,
"error": null
}200成功结果
{
"id": "TASK_ID",
"status": "succeeded",
"model": "gpt-image-2.5-flare",
"result": {
"assets": [
"https://example.com/output.png"
]
},
"error": null
}- 创建任务01
POST /v1/tasks提交 model + input,保存返回的任务 id。
202 · pending - 轮询状态02
GET /v1/tasks/{id}pending / processing 时等待并继续查询。
等待 → 再查询 - 读取终态03
result.assets[] / error按任务终态读取对应结果。
succeeded→ assetsfailed→ error
API 模型 ID 为 gpt-image-2.5-flare。本文说明平台的实际契约,调用前请核对实时目录中的可用性。
OpenAI 将文生图(Generations)和参考图编辑(Edits)分别组织。平台异步任务接口沿用同一端点,由输入内容区分两种场景。
| 文档 | 官方 Image API | 平台接口 |
|---|---|---|
| 文生图 | POST /v1/images/generations | POST /v1/tasks · input.prompt |
| 图生图 | POST /v1/images/edits | POST /v1/tasks · input.prompt + input.images |
把 https://example.com/reference.png 换成可公开访问的参考图 URL。这里使用平台的 images 数组,不是官方 multipart 的 image 字段。
平台地址在构建时填入,运行前设置 API_KEY 为服务端密钥。
curl "https://newrouters.com/v1/tasks" \ -H "Content-Type: application/json" \ -H "Authorization: Bearer $API_KEY" \ --data '{ "model": "gpt-image-2.5-flare", "input": { "quality": "medium", "resolution": "1k", "output_format": "jpeg", "prompt": "Keep the subject and replace the background with a quiet garden", "images": [ "https://example.com/reference.png" ] }}'创建响应表示任务已受理,不是最终结果。用返回的 ID 替换 TASK_ID,轮询至 succeeded 或 failed。
curl "https://newrouters.com/v1/tasks/TASK_ID" \ -H "Authorization: Bearer $API_KEY"成功查看 result,失败查看 error。上游结果未知时保留原任务 ID,不盲目重复提交付费生成。
| 字段 | 类型 | 要求 | 默认值 | 限制 |
|---|---|---|---|---|
size | string | 可选 | — | 原生尺寸参数,优先于 resolution 和 aspect_ratio;auto 或 宽x高。宽高为 16 倍数、最长边 ≤ 3840、长短边比 ≤ 3、总像素 655,360–8,294,400;详见尺寸说明 |
images | array | 本场景必填 | — | 最多项数 20 |
prompt | string | 必填 | — | 最大长度 100000 |
quality | enum | 可选 | "medium" | low, medium, high, xhigh, max, auto |
background | enum | 可选 | — | auto, transparent, opaque |
resolution | enum | 可选 | "1k" | 1k, 2k, 4k; 传入 size 时不生效 |
aspect_ratio | enum | 可选 | — | 21:9, 16:9, 3:2, 4:3, 5:4, 1:1, 4:5, 3:4, 2:3, 9:16 |
output_format | enum | 可选 | "jpeg" | png, jpeg, webp |
尺寸限制(size)
Section titled “尺寸限制(size)”以下官方输出尺寸规则适用于 GPT Image 2、GPT Image 2.5 Sunburst 和 Flare,文生图与图生图使用同一组规则。size 可为 auto,或 WIDTHxHEIGHT 格式的像素尺寸。
| 条件 | 官方限制 |
|---|---|
| 宽和高 | 均为 16 的正整数倍 |
| 最长边 | ≤ 3840 px |
| 长边 / 短边 | ≤ 3 |
| 总像素(宽 × 高) | 655,360–8,294,400 |
上述条件必须同时满足。官方将超过 2560x1440 的分辨率标为实验性。
| size | 是否符合官方规则 | 说明 |
|---|---|---|
| 1024x1024 | 合法 | 常用正方形 |
| 1536x864 | 合法 | 16:9 横图 |
| 2880x2880 | 合法 | 正方形总像素恰好达到上限 |
| 3840x2160 / 2160x3840 | 合法 | 横向 / 纵向 4K,总像素达到上限 |
| 1537x864 | 非法 | 宽度不是 16 的倍数 |
| 512x512 | 非法 | 总像素低于下限 |
| 3072x768 | 非法 | 长短边比为 4:1,超过 3:1 |
| 3840x3840 | 非法 | 总像素超过上限 |
| 4096x4096 | 非法 | 同时超过边长和总像素上限 |
平台尺寸参数
Section titled “平台尺寸参数”传入 size 后,resolution 和 aspect_ratio 不生效。size=auto(包括同时省略 size 和 aspect_ratio)按 2K 计费,即使同时传入 resolution=4k 也不会按 4K 计费或保证 4K 输出。具体 WxH 按 size 推导计价档位。需要指定分辨率档位时,请省略 size,使用 resolution + aspect_ratio。
resolution 是平台档位名称,4k 不等于 4096x4096。当前共用换算中,4k + 1:1 对应 2880x2880,4k + 16:9 对应 3840x2160;实际产物尺寸以渠道结果为准。平台同步 /v1/images/generations、/v1/images/edits 的 size 会转换到现有分辨率档位及最接近的支持比例,不能保证任意自定义 size 都按原值输出。
| resolution | aspect_ratio | 共用换算后的 size |
|---|---|---|
| 1k | 1:1 | 1024x1024 |
| 2k | 1:1 | 2048x2048 |
| 4k | 1:1 | 2880x2880 |
| 4k | 16:9 | 3840x2160 |
| 4k | 9:16 | 2160x3840 |
按平台推荐参数创建 4K 正方形任务时,input 中填写如下;不要同时传 size。
{ "resolution": "4k", "aspect_ratio": "1:1"}与官方的对应关系
Section titled “与官方的对应关系”对应官方 POST /v1/images/edits 场景。本文实际提交平台的异步 POST /v1/tasks 请求。 只使用平台 schema 支持的字段,不默认兼容全部官方参数。
官方来源与模型身份
Section titled “官方来源与模型身份”核对日期: 2026-09-27 · 平台模型: gpt-image-2.5-flare · 官方对应: gpt-image-2.5-flare
接入时核对当前可用性、契约和账号价格。排错时保留请求 ID 与消费凭据。 完整 API 参考