xAI's image generation models. Text-to-image and image editing.
Authorization: Bearer YOUR_API_KEY| Model | model | Price | Notas |
|---|---|---|---|
| Grok Imagine Image | grok-imagine/grok-imagine-image | $0.03/imagem | xAI Grok Imagine, texto para imagem + edição de imagens (~4s) |
| Grok Imagine Image Pro | grok-imagine-pro/grok-imagine-image-pro | $0.0800-$0.1200/imagem | Pro detail, native 1K/2K (2K default), text-to-image + multi-image edit (up to 3 refs, no extra charge) |
| Grok 4.2 Image | grok-4.2-image | $0.03/imagem | Merged into grok-imagine-image (same price, old name still works) |
# 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-imagine/grok-imagine-image",
"prompt": "A cute cat wearing a space helmet, digital art",
"aspect_ratio": "1:1",
"n": 1
}'
# Image editing (one reference image; aspect_ratio is ignored here)
curl -X POST https://apimodels.app/api/v1/images/generations \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "grok-imagine/grok-imagine-image",
"prompt": "Replace the cat with a golden retriever",
"image_url": "https://example.com/cat.png"
}'
# Multi-image editing (up to 3 references, Pro only)
curl -X POST https://apimodels.app/api/v1/images/generations \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "grok-imagine-pro/grok-imagine-image-pro",
"prompt": "Put the dog from <IMAGE_1> into the room from <IMAGE_0>",
"image_urls": ["https://example.com/room.png", "https://example.com/dog.png"],
"resolution": "2k"
}'
# Step 2: Poll status
curl "https://apimodels.app/api/v1/images/generations?task_id=TASK_ID" \
-H "Authorization: Bearer YOUR_API_KEY"| Field | Required | Type | Description |
|---|---|---|---|
| model | Yes | string | grok-imagine/grok-imagine-image / grok-imagine-pro/grok-imagine-image-pro(grok-4.2-image = grok-imagine-image 的别名) |
| prompt | Yes | string | Descrição de texto ou instruções de edição |
| image_url | No | string | Reference image URL or base64, for image editing |
| image_urls | No | string[] | grok-imagine-pro only: multiple reference images (up to 3, at no extra charge — price depends on resolution only). Refer to them as <IMAGE_0>, <IMAGE_1> in the prompt. More than 3 returns an error rather than silently dropping any. |
| image_base64 | No | string | Base64-encoded reference image, for image editing |
| resolution | No | string | grok-imagine-pro only: 1k or 2k (default 2k). Priced per tier: 1k $0.08, 2k $0.12. |
| aspect_ratio | No | string | grok-imagine and grok-imagine-pro: 1:1, 16:9, 9:16, 4:3, 3:4, 3:2, 2:3, 2:1, 1:2, 19.5:9, 9:19.5, 20:9, 9:20, auto (default 1:1; ignored when image is provided) |
| n | No | integer | Number of images: 1-10 (default 1; grok-imagine and grok-imagine-pro only support 1) |
| callback_url | No | string | URL do webhook chamada quando a tarefa é concluída |
Try it in the Playground
grok-imagine-image is $0.03 per image (text-to-image and editing, ~4s). grok-imagine-image-pro is tiered by resolution: 1K $0.08, 2K $0.12, with up to 3 reference images at no extra charge.
No — when a reference image is supplied, aspect_ratio is ignored and the output follows the input image ratio.