OpenAI gpt-image-2。同一端点同时支持文生图和多图编辑(最多 16 张参考图,单张 ≤ 30MB),输出构图由 aspect ratio 控制。原生 1K / 2K / 4K($0.025 / $0.04 / $0.06)。异步任务:POST 创建任务后用 GET 轮询或走 callback_url 回调。
Authorization: Bearer YOUR_API_KEY| 模型 | model | 价格 | 说明 |
|---|---|---|---|
| GPT Image 2 | gpt-image-2 | $0.025 / $0.04 / $0.06 | 异步 · 1K/2K/4K 分档 |
/api/v1/images/generations创建任务/api/v1/images/generations?task_id=...查询状态# ─── 1. Text-to-image ──────────────────────────────────────
# resolution: "1K" | "2K" | "4K" (optional, default 1K). aspect_ratio: 1:1, 3:2, 2:3, 4:3, 3:4, 16:9, 9:16.
curl -X POST https://apimodels.app/api/v1/images/generations \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-image-2",
"prompt": "A minimalist product shot of a white sneaker on a pastel gradient backdrop, soft studio lighting",
"aspect_ratio": "1:1",
"resolution": "2K"
}'
# Response:
# { "code": 200, "msg": "success", "data": { "taskId": "clxxx...", "state": "pending" } }
# ─── 2. Image editing with a reference URL ─────────────────
curl -X POST https://apimodels.app/api/v1/images/generations \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-image-2",
"prompt": "Place this product on a marble kitchen counter with soft morning light",
"image_url": "https://example.com/product.jpg",
"aspect_ratio": "3:2"
}'
# ─── 3. Multi-image fusion (up to 10 reference images) ─────
curl -X POST https://apimodels.app/api/v1/images/generations \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-image-2",
"prompt": "Use the model from image 1 wearing the outfit from image 2, studio lighting",
"image_urls": [
"https://example.com/model.jpg",
"https://example.com/outfit.jpg"
],
"aspect_ratio": "2:3"
}'
# ─── 4. Image editing via base64 ───────────────────────────
curl -X POST https://apimodels.app/api/v1/images/generations \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-image-2",
"prompt": "Add a geometric fox logo in the center of the mug",
"image_base64": "iVBORw0KGgoAAAANSUhEUgAA...",
"image_mime_type": "image/png",
"aspect_ratio": "1:1"
}'
# ─── 5. Poll task status ───────────────────────────────────
curl "https://apimodels.app/api/v1/images/generations?task_id=TASK_ID" \
-H "Authorization: Bearer YOUR_API_KEY"
# Success response:
# {
# "code": 200,
# "msg": "success",
# "data": {
# "taskId": "clxxx...",
# "state": "completed",
# "resultUrls": ["https://r2.apimodels.app/images/xxx.png"],
# "costTime": 14320,
# "completeTime": 1705123465000
# }
# }
# ─── 6. Webhook callback (optional) ────────────────────────
# Add "callback_url" to the create request and your endpoint
# will receive a POST with the same payload when the task
# completes — useful for production to avoid polling.
curl -X POST https://apimodels.app/api/v1/images/generations \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-image-2",
"prompt": "Studio photo of a ceramic mug",
"aspect_ratio": "1:1",
"callback_url": "https://your-domain.com/webhook/image"
}'| 字段 | 必填 | 类型 | 说明 |
|---|---|---|---|
| model | 是 | string | 必须为 "gpt-image-2" |
| prompt | 是 | string | 图片描述或编辑指令。多图编辑时可用 "image 1"、"image 2" 引用具体参考图。长度 1–20000 字符 |
| aspect_ratio | 否 | string | 输出画面比例,枚举:1:1 / 2:3 / 3:2 / 4:5 / 5:4 / 4:3 / 3:4 / 16:9 / 9:16 / 21:9。省略或传 "auto" 让模型自决。注意:5:4 和 4:5 仅在 1K 支持,2K/4K 下不支持(请改用 1K,或换 3:4 / 4:3)。 |
| resolution | 否 | string | "1K"(默认)/ "2K" / "4K"。分档计价:1K $0.025、2K $0.04、4K $0.06。 |
| image_url | 否 | string | 单张参考图 URL(公网可访问)。传入则走图生图,每张 ≤ 10MB |
| image_urls | 否 | string[] | 多张参考图 URL(最多 16 张,每张 ≤ 10MB),用于多图融合。超过 16 张会只取前 16 张 |
| image_base64 | 否 | string | Base64 编码或 data URI 的参考图(本地文件用)。和 image_url 二选一。 |
| image_mime_type | 否 | string | image_base64 对应的 MIME,默认 image/jpeg。支持 image/png、image/jpeg、image/webp |
| callback_url | 否 | string | 任务完成回调 URL。服务端会 POST 与轮询返回相同结构的 JSON 到这个地址 |
| 字段 | 必填 | 类型 | 说明 |
|---|---|---|---|
| code | — | integer | 200 表示创建/查询成功;其他值见错误码表 |
| msg | — | string | "success" 或错误描述 |
| data.taskId | — | string | 任务 ID,查询状态时用 |
| data.state | — | string | pending / processing / completed / failed |
| data.resultUrls | — | string[] | 仅在 state=completed 时返回;R2 托管的图片 URL,保留 7 天后自动删除,请及时下载或转存到自有存储 |
| data.failMsg | — | string | 仅在 state=failed 时返回,上游失败原因 |
| data.costTime | — | integer | 任务耗时(毫秒) |
| data.completeTime | — | integer | 完成时间戳(毫秒) |
相关:OpenAI SDK 兼容通道见 GPT Image 2 All;试一试:Playground
按分辨率分档:1K $0.025、2K $0.04、4K $0.06 每张,与比例、提示词长度无关。仅成功扣费。
调 POST /api/v1/images/generations,model 填 gpt-image-2,带 prompt + image_url(单张)或 image_urls[](最多 16 张)。GET ?task_id= 轮询到完成,或传 callback_url 收回调。
gpt-image-2 是异步任务通道(1K/2K/4K 分档);gpt-image-2-all 是 OpenAI SDK 兼容的同步通道,带完整质量矩阵和蒙版编辑;gpt-image-2-lite 是最便宜的通道:$0.008/张、仅 1K、同步。