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 kie.ai beta channel — an alternate upstream to our primary gpt-image-2 route. One endpoint handles text-to-image and multi-image editing (up to 16 references), aspect_ratio drives composition, NSFW filtering is on by default. Async, typical latency 15–40s.
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"
}
}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