通过统一的接口调用多家顶级图片生成模型,支持文生图、图片编辑、蒙版修复和多图融合。
所有请求需在 Header 中携带 Bearer Token:
Authorization: Bearer YOUR_API_KEY
/api/v1/images/generations创建图片生成任务
/api/v1/images/generations?task_id=xxx查询任务状态并获取图片链接
选择模型提供商查看对应的参数和示例
OpenAI GPT Image 2 通过 kie.ai beta 通道提供的备选上游。单一端点自动识别文生图 / 图生图,支持最多 16 张参考图的多图融合,aspect ratio 控图,自带 NSFW 过滤。异步任务,典型耗时 15-40 秒。
gpt-image-2-beta# ─── 1. Text-to-image ──────────────────────────────────────
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-beta",
"prompt": "A cinematic night-city poster with neon reflections on a rainy street",
"aspect_ratio": "16:9"
}'
# ─── 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-beta",
"prompt": "Transform this product shot into a premium e-commerce poster style",
"image_url": "https://example.com/product.jpg",
"aspect_ratio": "4:3"
}'
# ─── 3. Multi-image fusion (up to 16 references) ──────────
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-beta",
"prompt": "Dress the model from image 1 in the outfit from image 2",
"image_urls": [
"https://example.com/model.jpg",
"https://example.com/outfit.jpg"
],
"aspect_ratio": "3:4"
}'
# ─── 4. Enable safe-for-work filter (default is off) ──────
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-beta",
"prompt": "Family-friendly cartoon mascot",
"aspect_ratio": "1:1",
"nsfw_checker": true
}'
# ─── 5. Poll task status ───────────────────────────────────
curl "https://apimodels.app/api/v1/images/generations?task_id=TASK_ID" \
-H "Authorization: Bearer YOUR_API_KEY"
# ─── 6. Webhook (recommended for production) ──────────────
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-beta",
"prompt": "Studio photo of a ceramic mug on a marble counter",
"aspect_ratio": "1:1",
"callback_url": "https://your-domain.com/webhook/image"
}'{
"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.jpeg"],
"createTime": 1705123450000,
"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 次(指数退避 1s/2s/4s,单次超时 10s);如果仍未成功,后台会在 30 分钟内继续补偿重发,直到接收端返回 2xx。
POST {your callback_url}
Content-Type: application/json
{
"code": 200,
"msg": "success",
"data": {
"taskId": "clxxx...",
"model": "<provider>/<model_name>",
"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": 12345, // duration in ms
"completeTime": 1705123465000, // ms epoch
"createTime": 1705123450000 // ms epoch
}
}注意:data.param 与 data.resultJson 都是 JSON 字符串,使用前必须 JSON.parse 一次才能拿到对象。
{
"resultUrls": [
"https://r2.apimodels.app/images/xxx.png"
]
}resultUrls 为已上传至 Cloudflare R2 的图片 URL 数组。多图模型(如 SparkPix Image Edit、n>1 的 GPT Image 2 Lite)会返回多个;state=failed 时通常为 null 或 {"resultUrls":[]},请不要假设一定有链接。
app.post('/webhook/image', express.json(), (req, res) => {
const { taskId, state, param, resultJson, failMsg } = req.body.data
if (state === 'completed') {
const { resultUrls } = JSON.parse(resultJson)
console.log('image ready', taskId, resultUrls[0])
} else {
console.warn('image failed', taskId, failMsg)
}
res.status(200).end() // must be 2xx, otherwise we retry
})pending任务已排队,等待处理processing图片生成中completed生成成功,可获取图片链接failed生成失败400请求参数错误或缺失401API 密钥无效402积分不足404任务 ID 不存在500服务器内部错误