Access top image generation models through a unified API -- text-to-image, image editing, mask inpainting, and multi-image fusion.
Add Authorization header to all requests:
Authorization: Bearer YOUR_API_KEY
/api/v1/images/generationsCreate an image generation task
/api/v1/images/generations?task_id=xxxQuery task status and get image URL
Select a provider to see its parameters and examples
OpenAI gpt-image-2 via the cheapest yunwu.ai channel. Synchronous API: a single endpoint auto-routes to /v1/images/generations (text-to-image) or /v1/images/edits (image editing + mask). Supports 1K / 2K / 4K output with quality control, built-in moderation=low, flat $0.04 per image.
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"
}
}Pass callback_url in the create request. When the task reaches the completed or failed terminal state, our server sends a single HTTP POST to that URL with Content-Type: application/json (no signing header). Delivery is retried up to 3 times (exponential backoff 1s/2s/4s, 10s per attempt); if still unsuccessful, a background job keeps retrying for up to 30 minutes until your endpoint returns 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
}
}Note: data.param and data.resultJson are both JSON strings — call JSON.parse once on each to get the underlying object.
{
"resultUrls": [
"https://r2.apimodels.app/images/xxx.png"
]
}resultUrls is an array of Cloudflare R2-hosted image URLs. Multi-image models (SparkPix Image Edit, GPT Image 2 Lite with n>1) return more than one. When state=failed, resultJson is typically null or {"resultUrls":[]} — do not assume a link is present.
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
})pendingQueued, waiting to startprocessingImage is being generatedcompletedDone -- image URLs availablefailedGeneration failed400Bad Request -- invalid or missing parameters401Unauthorized -- invalid API key402Payment Required -- insufficient credits404Not Found -- task ID not found500Internal Server Error