Grok API for Imagine Image 2.0

Build text-to-image and image-editing workflows with grok-imagine-image-2.0. The xAI API supports configurable aspect ratio, resolution, output count, and response format through OpenAI-compatible image endpoints.
Create an xAI API Key
Cinematic abstract image-generation scene with a luminous glass sculpture and natural studio lighting

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.
Detailed coherent fantasy landscape illustrating prompt-driven image generation

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.
Reference-guided image editing workflow

OpenAI-Compatible Integration

Use the xAI REST endpoint directly or configure an OpenAI client with https://api.x.ai/v1 as its base URL.
Production integration for generated image assets
Validate media inputs and output settings before sending production requests.

Grok Imagine Image 2.0 API Capabilities

Dedicated image model

Set model to grok-imagine-image-2.0 for current Imagine Image 2.0 generation and editing.

Text-to-image generation

Send a prompt to /v1/images/generations 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 /v1/images/edits.

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 Authorization 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.
Create an xAI API Key
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.

Grok API FAQ

What is the Grok Imagine Image 2.0 API endpoint?

For image generation, send a bearer-authenticated POST request to https://api.x.ai/v1/images/generations. For image editing, use https://api.x.ai/v1/images/edits.

Which model name should I use?

Use grok-imagine-image-2.0 for current Grok Imagine Image 2.0 generation and editing requests.

How much does the Grok API cost for images?

xAI currently lists Imagine Image 2.0 output from $0.04 to $0.08 per generated image depending on resolution and quality. Image inputs are listed at $0.01 each. Confirm current pricing before deployment.

Can I generate more than one image per request?

Yes. xAI documents configurable output count with up to 10 images in one generation request.

Does the API support image-to-image workflows?

Yes. The image-editing endpoint accepts a public image URL or base64 data URI. Multi-image editing supports up to three source images.

Is the Grok image API OpenAI compatible?

The generation API can be called with an OpenAI client by setting the base URL to https://api.x.ai/v1 and supplying an xAI API key.

Is this page operated by or officially affiliated with xAI?

No. This is an independent developer guide. Grok, Imagine, and xAI names identify the model and provider; this page does not claim partnership, endorsement, or official API operation.

What does “imagine image 2.0 xAI API” refer to?

It refers to the grok-imagine-image-2.0 model exposed through xAI’s image generation and editing endpoints.

Start Your Grok Image API Integration