通过统一的接口调用多家顶级图片生成模型,支持文生图、图片编辑、蒙版修复和多图融合。
所有请求需在 Header 中携带 Bearer Token:
Authorization: Bearer YOUR_API_KEY
/api/v1/images/generations创建图片生成任务
/api/v1/images/generations?task_id=xxx查询任务状态并获取图片链接
选择模型提供商查看对应的参数和示例
OpenAI gpt-image-2 通过 yunwu.ai 接入的最便宜通道。同步 API:同一端点自动在 /v1/images/generations(文生图) 和 /v1/images/edits(图生图 + mask) 之间路由。支持 1K / 2K / 4K 输出与 quality 控制,内置 moderation=low,扁平 $0.04/张。
gpt-image-2-lite# ─── 1. Text-to-image (1024x1024, low quality, jpeg) ──────
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-lite",
"prompt": "A children'"'"'s book drawing of a veterinarian using a stethoscope to listen to the heartbeat of a baby otter.",
"size": "1024x1024",
"quality": "low",
"output_format": "jpeg"
}'
# Response (sync — image URL returned directly):
# { "code": 200, "msg": "success", "data": { "taskId": "clxxx", "state": "completed", "resultUrls": ["https://r2.apimodels.app/..."] } }
# ─── 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-lite",
"prompt": "Change the season to winter with snow",
"image_url": "https://example.com/landscape.jpg",
"size": "1536x1024"
}'
# ─── 3. Multi-image fusion 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-lite",
"prompt": "Combine the model from image 1 with the outfit from image 2",
"image_base64": "BASE64_IMAGE_1",
"image_urls": ["https://example.com/outfit.jpg"],
"size": "1024x1536"
}'
# ─── 4. Mask inpainting (regenerate masked region only) ───
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-lite",
"prompt": "Replace the logo on the box",
"image_base64": "BASE64_IMAGE",
"mask_base64": "BASE64_MASK_PNG",
"size": "1024x1024"
}'
# ─── 5. Poll status (lite is sync, this returns completed) ─
curl "https://apimodels.app/api/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.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服务器内部错误