Image generation (async, job-based) backed by xAI Grok Imagine Image, Standard tier. Text-to-image needs only a prompt; for an edit put the references in image or images (a URL, a data: URI or base64), or call /v1/images/edits. Submitting returns a job id at once (HTTP 202); poll GET /v1/images/jobs/{id} for the image. Seven aspect ratios and two resolutions, 1K and 2K (send resolution: "2K" or a 2048-class size for 2K; 4K is not offered and is refused at submit); 1K usually renders in 5-10 seconds. On the Standard tier an edit keeps the original image's aspect ratio, and a different ratio is centre-cropped. 1K and 2K cost the same; failed requests are not charged.
Try in Playground →Authentication
Authorization: Bearer YOUR_API_KEY Content-Type: application/json
Create an API Key in the console to start.
Request body
| Parameter | Type | Required | Description |
|---|---|---|---|
| model | string | Yes | Model ID, here grok-imagine-image. |
| prompt | string | Yes | Text prompt describing the image. |
| size | string | No | Output aspect ratio. Recommended: pass a ratio — 1:1, 3:4, 2:3, 9:16, 4:3, 3:2, 16:9 — and the model renders natively at that ratio with no subject cropping. Pixel sizes (e.g. 1024x1024, 1024x1536, 1536x1024) are also accepted. Default 1:1 (square). |
| n | integer | No | Number of images, default 1. |
| image | string | No | Image-to-image: a reference image as a public URL, a data: URI, or raw base64. When present the request runs true identity-preserving image-to-image at the chosen size/ratio — equivalent to calling /v1/images/edits. |
| images | array | No | Multi-image reference (up to 8; ≤4 recommended for subject consistency): pass an array of strings, or an array of [{"image_url": "..."}] objects; each item a public URL, a data: URI, or base64. Runs multi-reference image-to-image (fusing the subjects and style of several references) - equivalent to multi-image input of /v1/images/edits. For a single reference the image field above also works. |
| resolution | string | No | Resolution: 1K (default) or 2K, at the same price. A 2048-class pixel size in size also selects 2K. 4K is not offered and is refused. |
Request example
# 1) submit -> 202 {"id":"img_...","status":"queued"}
curl https://nezhagate.com/v1/images/generations -H 'Authorization: Bearer YOUR_API_KEY' -H 'Content-Type: application/json' -d '{"model": "grok-imagine-image", "prompt": "a serene ink-wash poster, lots of negative space", "size": "1024x1536"}'
# 2) poll until status=succeeded
curl https://nezhagate.com/v1/images/jobs/img_3f9a...c2 -H 'Authorization: Bearer YOUR_API_KEY'Response
{
"id": "img_3f9a...c2",
"object": "image.generation.job",
"status": "queued",
"model": "grok-imagine-image"
}Image-to-Image
Image-to-image: put the reference in `image` (a public URL, a data: URI, or raw base64) to run true identity-preserving i2i — the model regenerates from it at the chosen size/ratio. Equivalent to calling /v1/images/edits.
curl https://nezhagate.com/v1/images/generations -H "Authorization: Bearer YOUR_API_KEY" -H "Content-Type: application/json" -d '{"model": "grok-imagine-image", "prompt": "replace the background with a starry sky", "image": "https://example.com/ref.png", "size": "3:4"}'Image jobs (submit → poll for the result)
Image rendering usually takes 1–3 minutes, so the image endpoints are job-only: submitting a request returns a job id immediately (HTTP 202); poll for the result with that id — the server keeps rendering across restarts, so the image is never lost. Same for text-to-image and image-to-image. (The old "async": true field is no longer needed; it is accepted but ignored.)
curl https://nezhagate.com/v1/images/generations -H 'Authorization: Bearer YOUR_API_KEY' -H 'Content-Type: application/json' -d '{"model": "grok-imagine-image", "prompt": "an ink-wash poster with lots of negative space", "size": "3:4"}'{ "id": "img_3f9a...c2", "object": "image.generation.job", "status": "queued", "model": "grok-imagine-image" }curl https://nezhagate.com/v1/images/jobs/img_3f9a...c2 -H 'Authorization: Bearer YOUR_API_KEY'
{
"id": "img_3f9a...c2",
"object": "image.generation.job",
"status": "succeeded",
"model": "grok-imagine-image",
"data": [{ "url": "https://img.nezhagate.com/i/9f86d081a8....png" }]
}🕑 data[0].url is a link on our image host that is kept for 60 days and then deleted automatically; to keep using it, download it and store it on your own storage or CDN.
status is one of queued / processing / succeeded / failed. On success the response carries data[].url. A job can only be polled by the account that created it. Image endpoints are always async — submit returns a job id; "async": true is accepted only for backward compatibility and ignored.
Error codes
Every error body carries error.message / error.type / error.code / error.param - branch on code; the full list is in the integration guide.
| HTTP | code | Description |
|---|---|---|
| 401 | invalid_api_key | API Key missing or invalid |
| 402 | insufficient_quota | Insufficient balance or Key over quota |
| 400 | invalid_request | Unsupported model or parameter |
| 429 | rate_limit_exceeded | Upstream rate limit |
| 502 | upstream_error | All upstream routes failed |