这是超分版:2K 和 4K 是先生成较小的图、再放大到目标尺寸(超分),细节和纹理不如原生 2K / 4K。适合测试任务、批量预览、对画面细节要求不高的生图。需要印刷级细节、小字清晰或原生 4K 的场景,请用 gpt-image-2。
文生图和参考图编辑,请求格式与 gpt-image-2 相同。1K / 2K / 4K 三档输出。异步任务:POST 创建任务后用 GET ?task_id= 轮询,或传 callback_url 等回调。
所有请求都要带 Authorization 请求头:
Authorization: Bearer YOUR_API_KEY
| 分辨率 | 每张价格 | 输出 |
|---|---|---|
| 1K | $0.01 | 约 100 万像素(如 1:1 为 1024x1024) |
| 2K | $0.015 | 先生成较小的图,再放大到 2K |
| 4K | $0.02 | 先生成较小的图,再放大到 4K |
按张计费,单位美元。价格只由分辨率决定,与 quality、画面比例、提示词长度无关。失败不扣费。
/api/v1/images/generations创建图片任务(文生图;带参考图时为图片编辑)。
/api/v1/images/generations?task_id=xxx查询任务状态,获取图片 URL。
| 分辨率 | aspect_ratio |
|---|---|
| 1K | 1:1 / 2:3 / 3:2 / 4:5 / 5:4 / 4:3 / 3:4 / 16:9 / 9:16 / 21:9 |
| 2K | 1:1 / 2:3 / 3:2 / 4:3 / 3:4 / 16:9 / 9:16 / 21:9 |
| 4K | 1:1 / 2:3 / 3:2 / 4:3 / 3:4 / 16:9 / 9:16 / 21:9 |
5:4 和 4:5 仅 1K 支持。2K / 4K 下请改用 1K,或换成 4:3 / 3:4。
# Create task: 2K, 16:9 text-to-image
curl -X POST https://api.apimodels.app/v1/images/generations \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-image-2-upscaled",
"prompt": "A cherry blossom tree by a tranquil river at dawn, soft light",
"aspect_ratio": "16:9",
"resolution": "2K"
}'
# Response:
# { "code": 200, "msg": "success", "data": { "taskId": "clxxx...", "state": "pending" } }
# Poll task status
curl "https://api.apimodels.app/v1/images/generations?task_id=TASK_ID" \
-H "Authorization: Bearer YOUR_API_KEY"{
"code": 200,
"msg": "success",
"data": {
"taskId": "clxxx...",
"state": "pending"
}
}{
"code": 200,
"msg": "success",
"data": {
"taskId": "clxxx...",
"state": "completed",
"resultUrls": ["https://r2.apimodels.app/images/xxx.png"],
"costTime": 14320,
"completeTime": 1705123465000
}
}{
"code": 200,
"msg": "success",
"data": {
"taskId": "clxxx...",
"state": "failed",
"failMsg": "Content policy violation"
}
}在创建请求中传 callback_url。任务到达 completed 或 failed 终态时,服务器向该地址发送 HTTP POST(Content-Type: application/json,无签名头)。投递失败会按指数退避最多重试 3 次(每次超时 10 秒);仍未成功时,后台任务会在 30 分钟内继续重试,直到你的接口返回 2xx。
POST {your callback_url}
Content-Type: application/json
{
"code": 200,
"msg": "success",
"data": {
"taskId": "clxxx...",
"model": "gpt-image-2-upscaled",
"state": "completed" | "failed",
"param": "<JSON string>", // request params, JSON.parse once
"resultJson": "<JSON string> | null", // result object, JSON.parse once
"failCode": null | "string",
"failMsg": null | "string",
"costTime": 14320, // duration in ms
"completeTime": 1705123465000, // ms epoch
"createTime": 1705123450000 // ms epoch
}
}注意:data.param 和 data.resultJson 都是 JSON 字符串,各需 JSON.parse 一次。resultJson 解析后为 { "resultUrls": ["https://..."] };state=failed 时通常为 null 或 {"resultUrls":[]}。
pending已排队processing生成中completed完成,可取 resultUrlsfailed失败,不扣费400请求错误:参数缺失或无效401未授权:API 密钥无效402余额不足404任务 ID 不存在500服务器内部错误