Navigating the xAI Image Generation API: Aspect Ratios, the quality Parameter, and the Retirement of grok-imagine-image-quality
When building visual pipelines with the xAI API (/v1/images/generations), controlling framing and fidelity comes down to how you configure aspect_ratio, resolution, and quality—as well as which model slug you target. Following xAI’s November 2026 platform updates, the way quality tiers and model slugs interact shifted significantly.
1. From grok-imagine-image-quality to grok-imagine-image-2.0
Effective November 2, 2026, xAI officially retired the grok-imagine-image-quality model slug. Rather than maintaining separate model endpoints for standard versus high-fidelity output, xAI consolidated its image generation capabilities into grok-imagine-image-2.0 and introduced an explicit quality parameter.
- Zero-Downtime Redirect: Existing code still pointing to
grok-imagine-image-quality(or the oldergrok-imagine-image-proalias) will not break. Requests to/v1/images/generationsand/v1/images/editsautomatically route togrok-imagine-image-2.0withqualitypinned to"low". - Lower Cost: Routing to
grok-imagine-image-2.0at"low"quality reduces generation costs by $0.01 per image across every resolution compared to the legacygrok-imagine-image-qualityrates. Note that the originalgrok-imagine-image(1.0) model remains unaffected by this retirement. - Verifying the Switch: You can confirm the redirect in production by inspecting
usage.cost_in_usd_tickson JSON responses—which reflects $0.04 per 1K image and $0.06 per 2K image—or by checking gRPC responses in the xAI SDK, which report the model string asgrok-imagine-image-2.0-low.
2. Controlling Output Fidelity with quality and resolution
On grok-imagine-image-2.0, visual output is governed by two independent dimensions: quality (rendering fidelity) and resolution (pixel dimensions).
The quality Parameter
Supported exclusively on grok-imagine-image-2.0, quality accepts three values:
auto(Default): Lets the API select the tier dynamically based on the endpoint. Currently,autodefaults tolowfor text-to-image generation (/v1/images/generations) andmediumfor image editing (/v1/images/edits).low: Delivers fast, cost-efficient generation ($0.04 at 1K; $0.06 at 2K). Despite its name, this tier matches the capability profile that replacedgrok-imagine-image-quality.medium: Recommended when fine textures, small objects, or intricate details must remain crisp and recognizable.
The resolution Parameter
Independent of quality, resolution accepts 1k (the default when omitted) or 2k. For production assets that require sharp detail—such as product mockups or hero banners—xAI’s prompting guidelines recommend explicitly pinning quality: "medium" alongside resolution: "2k".
3. Framing Your Output with aspect_ratio
Instead of requiring exact pixel dimensions, the xAI Image API uses semantic aspect ratios via the aspect_ratio parameter. If you omit aspect_ratio, it defaults to auto, allowing the model to infer the most natural framing from your prompt.
| Aspect Ratio | Primary Use Case |
|---|---|
1:1 |
Social media posts, avatars, and square thumbnails |
16:9 / 9:16 |
Standard widescreen video, desktop wallpapers, and vertical mobile stories |
4:3 / 3:4 |
Slide presentations and traditional portraits |
3:2 / 2:3 |
Classic DSLR photography framing |
2:1 / 1:2 |
Web headers and vertical banners |
19.5:9 / 9:19.5 |
Full-screen layouts for modern iPhone displays |
20:9 / 9:20 |
Full-screen layouts for modern Android displays |
21:9 |
Cinematic ultrawide framing |
5:2 |
Extra-wide website hero banners |
auto |
Dynamic ratio selection based on prompt context |
(Note: 21:9 and 5:2 were introduced specifically with grok-imagine-image-2.0 and are not supported on legacy v1 models.)
4. Practical Implementation Examples
Whether you use the REST API, the official xAI Python SDK, or an OpenAI-compatible client, migrating to grok-imagine-image-2.0 requires only a single-line model update while unlocking explicit aspect_ratio and quality controls.
REST API (cURL)
curl -X POST https://api.x.ai/v1/images/generations
-H "Authorization: Bearer $XAI_API_KEY"
-H "Content-Type: application/json"
-d '{
"model": "grok-imagine-image-2.0",
"prompt": "A minimalist ceramic pour-over coffee dripper on an oak counter, morning sunlight from the left",
"aspect_ratio": "3:2",
"resolution": "2k",
"quality": "medium",
"response_format": "b64_json",
"n": 1
}'
Official xAI Python SDK
import xai_sdk
client = xai_sdk.Client()
response = client.image.sample(
prompt="A minimalist ceramic pour-over coffee dripper on an oak counter, morning sunlight from the left",
model="grok-imagine-image-2.0",
aspect_ratio="3:2",
resolution="2k",
quality="medium",
)
print(response.url)
5. Production Best Practices
- Persist
b64_jsonWhen Needed: By default,response_formatis set to"url", which returns temporary hosted links. If your application needs to store the generated assets permanently without writing an immediate download worker, request"b64_json". - Batching and Async Execution: Use the
nparameter (1–10)—orclient.image.sample_batch(n=...)in the xAI Python SDK—to generate variations of a single prompt. For high-volume workloads or long-running batches, pass"deferred": trueto immediately receive arequest_idfor polling (GET /v1/images/{request_id}) or webhook delivery (image.generation.completed) rather than holding an HTTP connection open.
Leave a Reply