Grok Imagine Image 2.0 Image Generation
- Grok Imagine Image 2.0 (grok-imagine-image-2.0) is xAI’s image generation and editing model — text-to-image and image editing share the same model name
- Omit
image_urlsfor text-to-image; pass1~3reference images and it automatically switches to image editing, no model change needed - Asynchronous processing mode, use the returned task ID to query
- Generated image links are valid for 24 hours, please save them promptly
Authorizations
##All APIs require Bearer Token authentication##
Get API Key:
Visit API Key Management Page to get your API Key
Add to request header:
Body
Image generation model name. Text-to-image and image editing share this model name; the mode switches automatically depending on whether image_urls is provided
grok-imagine-image-2.0 "grok-imagine-image-2.0"
Prompt describing the image you want to generate, or how to edit the reference images you provide
Multi-image reference syntax:
- When passing multiple reference images, use
<IMAGE_0>,<IMAGE_1>,<IMAGE_2>in the prompt to refer to the 1st, 2nd and 3rd reference image respectively - Indexes start at
0and map one-to-one to the order of theimage_urlsarray - Example:
Place the person from <IMAGE_0> into the scene of <IMAGE_1>
"Cyberpunk Tokyo street at night, neon lights reflecting on the wet pavement"
Reference image URL list for image-to-image and image editing functions
Note:
- Number of input images per request:
0~3(omitted = text-to-image,1~3= image editing) - Only publicly accessible
http/httpsimage URLs are supported; base64 and data URLs are not supported - Supported file formats:
.jpeg,.jpg,.png,.webp - Image URLs must be directly accessible by the server, or the image URL should directly download when accessed (typically these URLs end with image file extensions, such as
.png,.jpg) - In image editing scenarios the reference images incur an additional charge, counted once per request and not multiplied by
n
3Aspect ratio of the generated image, defaults to auto
Supported ratios (13):
Note:
auto: the model decides the ratio itself; omitting this parameter is equivalent toauto(output is usually portrait)- Values outside the table above are not supported
1:1, 4:3, 3:4, 3:2, 2:3, 16:9, 9:16, 2:1, 1:2, 19.5:9, 9:19.5, 20:9, 9:20, auto "16:9"
Pixel tier of the output image, defaults to 1K; supports the 1K and 2K tiers
Note:
- This model does not support
4K - Values are case-insensitive
1K, 2K "1K"
Generation quality tier, controls how deeply the model thinks, defaults to medium
Note:
- This model only supports the
low/mediumtiers; other values such ashighare not supported quality(quality tier) andresolution(pixel tier) are independent and can be combined freely- Values are case-insensitive
low, medium "medium"
Number of images to generate, range 1~10, defaults to 1
Note:
- Each image is billed independently, cost grows linearly with
n - The additional charge for reference images is counted once per request and is not multiplied by
n - When the task completes,
result_urlsreturnsnindependent image links
1 <= x <= 101
HTTPS callback address after task completion
Callback Timing:
- Triggered when task is completed, failed, or cancelled
- Sent after billing confirmation is completed
Security Restrictions:
- Only HTTPS protocol is supported
- Callback to internal IP addresses is prohibited (127.0.0.1, 10.x.x.x, 172.16-31.x.x, 192.168.x.x, etc.)
- URL length must not exceed
2048characters
Callback Mechanism:
- Timeout:
10seconds - Maximum
3retries on failure (retries after1second/2seconds/4seconds) - Callback response body format is consistent with the task query API response format
- Callback address returning 2xx status code is considered successful, other status codes will trigger retry
"https://your-domain.com/webhooks/image-task-completed"
Response
Image generation task created successfully
Task creation timestamp
1757156493
Task ID
"task-unified-1757156493-imcg5zqt"
Actual model name used
"grok-imagine-image-2.0"
Specific task type
image.generation.task Task progress percentage (0-100)
0 <= x <= 1000
Task status
pending, processing, completed, failed "pending"
Asynchronous task information
Task output type
text, image, audio, video "image"
Usage and billing information