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
xAI's image generation model. Supports text-to-image, URL-based image editing, and mask inpainting for precise region replacement.
grok-image/grok-4.2-imagegrok-imagine/grok-imagine-imagegrok-imagine-pro/grok-imagine-image-pro# Step 1: Create task (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": "grok-image/grok-4.2-image",
"prompt": "A cute cat wearing a space helmet, digital art",
"size": "1024x1024",
"n": 1
}'
# Mask inpainting (base64 image + mask)
curl -X POST https://apimodels.app/api/v1/images/generations \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "grok-image/grok-4.2-image",
"prompt": "Replace with a golden retriever",
"image": "BASE64_ENCODED_IMAGE",
"mask": "BASE64_ENCODED_MASK",
"size": "1024x1024"
}'
# Step 2: Poll status
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