OpenAI 兼容的 GPT Image 2 同步图片 API —— OpenAI SDK / Codex / Cursor 改一行 base_url 即可直连。完整分辨率 × 质量矩阵(1K/2K/4K × low/medium/high/auto),文生图 + 多图编辑(最多 16 张参考图 + mask),同步返回、无需轮询。
所有请求在 Header 携带 API Key:
Authorization: Bearer YOUR_API_KEY| 字段 | 必填 | 类型 | 说明 |
|---|---|---|---|
| 档位 | low | medium / auto | high |
| 1K | $0.005 | $0.025 | $0.07 |
| 2K | $0.01 | $0.04 | $0.10 |
| 4K | $0.015 | $0.06 | $0.23 |
按张计费,quality=auto 按 medium 档收费;失败不扣费。生成速度随质量档变化:low 约 40 秒、medium 约 60-90 秒、high 约 2 分钟。
| 字段 | 必填 | 类型 | 说明 |
|---|---|---|---|
| 计费档 | 典型 size | 判定规则 | |
| 1K | 1024x1024 / 1536x1024 / 1024x1536 | 长边 ≤ 1536 | |
| 2K | 2048x2048 / 2048x1152 / 1152x2048 | 长边 1537-2048 | |
| 4K | 3840x2160 / 2160x3840 | 长边 > 2048 |
任意自定义 WxH 也支持:两边为 16 的倍数、最长边 ≤ 3840、长宽比 ≤ 3:1、总像素 65.5 万-829 万。也可以不传 size,改传 aspect_ratio + resolution(1K/2K/4K),由服务端算出最优尺寸。
/api/v1/images/generations·POST/api/v1/images/edits传 OpenAI 风格的 WxH size 即触发同步模式:请求直接返回图片(b64_json + url),与 OpenAI 官方 images.generate() / images.edit() 契约一致。
# Text-to-image — OpenAI Images API shape, SYNC response (no task 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-all",
"prompt": "a white sneaker product shot on beige background, studio light",
"size": "2048x2048",
"quality": "medium",
"n": 1
}'
# → { "created": ..., "data": [{ "b64_json": "...", "url": "https://r2.apimodels.app/..." }] }
# Image edit / multi-image fusion — multipart, OpenAI images.edit() shape
curl -X POST https://apimodels.app/api/v1/images/edits \
-H "Authorization: Bearer YOUR_API_KEY" \
-F "model=gpt-image-2-all" \
-F "image=@product.png" \
-F "prompt=put this sneaker on a model, e-commerce close-up" \
-F "size=2048x2048" \
-F "quality=medium"不传 WxH size(或需要 callback_url)时走平台统一异步契约:创建返回 taskId,轮询到 completed 取结果,支持 webhook 回调。
# Native async contract — pass aspect_ratio + resolution tier instead of size.
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-all",
"prompt": "a lighthouse on a cliff at dusk",
"aspect_ratio": "9:16",
"resolution": "2K",
"quality": "medium",
"callback_url": "https://your-domain.com/webhook"
}'
# → { "code": 200, "data": { "taskId": "..." } }
curl "https://apimodels.app/api/v1/images/generations?task_id=TASK_ID" \
-H "Authorization: Bearer YOUR_API_KEY"| 字段 | 必填 | 类型 | 说明 |
|---|---|---|---|
| 字段 | 类型 | 说明 | |
| model | string | gpt-image-2-all | |
| prompt | string | 提示词(必填) | |
| size | string | WxH,触发同步模式;见上方尺寸表 | |
| quality | string | low / medium / high / auto(默认 medium;auto 按 medium 计费) | |
| aspect_ratio + resolution | string | 异步模式下代替 size:比例 + 1K/2K/4K 档 | |
| image / image_base64 / image_url | string | 参考图 → 自动走编辑端点 | |
| image_urls / images | string[] | 多图融合,最多 16 张 | |
| mask_url / mask_base64 | string | 遮罩局部重绘(透明区域=重绘处) | |
| background | string | transparent / opaque / auto | |
| response_format | string | b64_json(默认)或 url(仅 /images/edits) | |
| n | number | 生成数量(计费 × n) |
试一试:Playground