grok-imagine-image-2.0. The xAI API supports configurable aspect ratio, resolution, output count, and response format through OpenAI-compatible image endpoints.Grok API for Imagine Image 2.0
Build text-to-image and image-editing workflows with
Create an xAI API Key
Choose the Right Grok Image Workflow
Text-to-Image Generation
Send a prompt with the grok-imagine-image-2.0 model and configure aspect ratio, resolution, output count, and response format for your application.

Natural-Language Image Editing
Submit a public image URL or base64 data URI with an edit prompt. Multi-image editing supports up to three source images in one request.

OpenAI-Compatible Integration
Use the xAI REST endpoint directly or configure an OpenAI client with https://api.x.ai/v1 as its base URL.

Validate media inputs and output settings before sending production requests.
Grok Imagine Image 2.0 API Capabilities
Dedicated image model
Set <code>model</code> to <code>grok-imagine-image-2.0</code> for current Imagine Image 2.0 generation and editing.
Text-to-image generation
Send a prompt to <code>/v1/images/generations</code> and request up to 10 generated images in one call.
Configurable output
Choose an aspect ratio, 1K or 2K resolution, output count, and supported response format.
Image editing
Send an edit instruction plus a public image URL or base64-encoded data URI to <code>/v1/images/edits</code>.
Up to three edit references
Multi-image editing accepts up to three source images for composition, subject combination, and style guidance.
Bearer authentication
Send an xAI API key in the <code>Authorization</code> header and keep credentials out of browser code, logs, and repositories.
xAI uses flat per-image pricing, with resolution and quality affecting the output fee.
Grok API Pricing for Imagine Image 2.0
Generation output pricing
xAI currently lists Imagine Image 2.0 output at $0.04 per image for 1K Low, $0.06 for 2K Low, $0.06 for 1K Medium, and $0.08 for 2K Medium.
Media input pricing
Image input for the Imagine Image 2.0 route is listed at $0.01 per input image; edits therefore include input-image and generated-output charges.
Prompt length does not set image cost
Image generation uses flat per-image pricing rather than token-based prompt billing. Multiply your requested image count by the selected output tier, then add any image-input charges for edits.
Recheck live pricing
Review the current xAI pricing page before production deployment because model tiers and billing terms can change.
Integrate the Grok Image API
1
1. Create and protect an API key
Create a key in the xAI console and send it as
Authorization: Bearer $XAI_API_KEY. Keep the key server-side. 2
2. Choose generation or editing
Use
/v1/images/generations for prompt-only creation. Use /v1/images/edits when a source image should guide or be transformed. 3
3. Build a validated request
Set
model to grok-imagine-image-2.0, add the prompt, and explicitly choose only the output options your product supports. 4
4. Submit and inspect the response
Check the HTTP status and response body before persisting returned URLs or base64 data. Do not assume every response contains a usable image.
5
5. Download and retain assets intentionally
Copy completed assets into your own approved storage when long-term availability matters, and handle retries idempotently to avoid duplicate charges.
Use the API where repeatable prompt and edit workflows matter more than a manual image editor.
What Developers Build with Grok Imagine Image 2.0
Campaign creative variants
Generate multiple visual directions for ads, landing pages, and social campaigns from structured prompt templates.
Product and concept visualization
Turn product briefs, environment descriptions, and art direction into review-ready image concepts.
Reference-guided edits
Transform approved source images with natural-language instructions while preserving the original asset in your workflow.
Localized visual production
Adapt prompt details for regions, formats, and channels while keeping request validation and asset tracking consistent.
Endpoints, pricing, model identity, image inputs, and platform relationship.
