Overview
Grok Imagine Image 2.0 supports text-to-image generation and image-to-image editing. Each successful task returns one image.Endpoint and authentication
Base URL:
Include
Authorization: Bearer YOUR_API_KEY on every request and Content-Type: application/json when submitting JSON.
Copy-paste async quickstart
Image-to-image
Provide 1–5 publicly accessible reference URLs. The prompt is optional; include it to describe the desired edit. Omittingaspect_ratio uses auto.
Parameters
string
default:"async"
Result delivery mode. Supported values:
async, callback. Omit this field or use async to poll for the result.string
Required when
request_type is callback. Provide a public HTTPS URL that receives the final task payload. See Webhooks.object
required
Grok Imagine Image 2.0 input parameters.
Poll for result
data.state is pending or processing. Stop at success or failed.
Successful response:
resultJson is a JSON string, so parse it before reading the image URL:
Status response fields
Failed task example
data.state, and retain the task ID when requesting support.
Webhook callback mode
Setrequest_type to callback and provide callback_url; the model input is unchanged.
Billing
Both modes cost $0.04 per generated image, with one output image per successful task. Reference images do not add an input charge. Failed tasks are refunded.
The market display reference is a comparison value and does not affect the amount charged.
New non-LLM requests use 1 credit =
$0.001. Calculate the full request amount, apply any applicable account discount, then round the total upward to the next whole credit. Agreed fixed unit prices retain their precision and replace the standard price and discount; final rounding still applies. Without discounts, one successful task costs 40 credits. See credit conversion and rounding and current API prices.
Latency and polling
Generation time varies with prompt complexity, image access, and queue load. The following intervals are client recommendations, not latency guarantees.
Use callback mode for completion notifications. Stop polling at a terminal state, and save important outputs promptly.
Errors and troubleshooting
- Missing
mode, a missing or blank text-to-imageprompt, an overlong prompt, an invalid aspect ratio, or an invalid image-to-image reference list causes a validation error. - Use reference URLs that are accessible without authentication. If generation fails, inspect
failCodeandfailMsg. - Check your API key for authentication errors and your balance for insufficient-balance errors.
- Back off on rate limits. Do not resubmit an accepted task just because it is still processing; continue polling its task ID.
MCP integration
The complete model schema declares result decoding inmcp.result and supported file bindings in mcp.attachments. These are client integration metadata, not generation input parameters. Attachment path: image_urls. Preserve the user’s file order. Model parameter validation remains on the API.