Mastering xAI Image Generation: Aspect Ratios, Quality Tiers, and the grok-imagine-image-2.0 Transition
Building visual pipelines with xAI’s Grok image APIs requires understanding how framing, rendering fidelity, and model versioning interact. Whether you are generating dynamic social assets, widescreen cinematic frames, or high-resolution product mockups, xAI’s /v1/images/generations endpoint provides granular control through parameters like aspect_ratio, resolution, and quality—alongside an important architectural shift following the November 2, 2026 retirement of the legacy grok-imagine-image-quality slug.
Controlling Dimensions with aspect_ratio
Rather than forcing developers to calculate exact pixel dimensions and risk distortion or awkward cropping, the xAI Image Generation API standardizes framing through the aspect_ratio parameter. When omitted, the parameter defaults to auto, allowing the model to infer the most natural composition from the semantics of your text prompt.
When your layout demands strict dimensional consistency across a batch or series, xAI supports 15 explicit ratios tailored to modern screens and print formats:
| Aspect Ratio | Primary Use Case |
|---|---|
1:1 |
Square social media feeds, avatars, and thumbnails |
16:9 / 9:16 |
Standard widescreen video, desktop wallpapers, and vertical stories |
4:3 / 3:4 |
Presentation slides and classic portrait framing |
3:2 / 2:3 |
Traditional DSLR/mirrorless photography and editorial layouts |
2:1 / 1:2 |
Website hero headers and vertical banners |
19.5:9 / 9:19.5 |
Full-bleed modern iPhone displays |
20:9 / 9:20 |
Full-bleed modern Android smartphone displays |
21:9 |
Anamorphic and cinematic widescreen compositions |
5:2 |
Ultra-wide web banners and panoramic headers |
auto |
Default mode; lets the model choose framing based on prompt intent |
For multi-image series where visual cohesion matters, locking aspect_ratio (such as 3:2 for photographic sequences) ensures consistent framing across every generated asset.
The Retirement of grok-imagine-image-quality
If you have worked with older xAI documentation or codebases, you may recognize the model identifier grok-imagine-image-quality (as well as grok-imagine-image-pro). Following a 60-day deprecation window announced on September 2, 2026, xAI officially retired the grok-imagine-image-quality model slug on November 2, 2026.
Rather than breaking existing production pipelines, xAI implemented a seamless server-side redirect:
- Automatic Routing: Requests sent to
grok-imagine-image-quality(orgrok-imagine-image-pro) on/v1/images/generationsand/v1/images/editsare automatically served bygrok-imagine-image-2.0configured withquality: "low". - Backward Compatibility: Request payloads and response schemas remain identical, meaning legacy integrations continue functioning without downtime while gaining access to newer aspect ratios like
21:9and5:2. - Lower Cost: Running on
grok-imagine-image-2.0atlowquality is $0.01 cheaper per image across every resolution tier than the retired model slug ($0.04 per 1K image and $0.06 per 2K image).
Balancing Speed, Detail, and Cost with quality and resolution
With grok-imagine-image-2.0 unifying xAI’s still-image capabilities, quality management moved from a separate model slug into an explicit request parameter. You can now tune output fidelity and compute spend independently across two axes:
quality(low,medium,auto): Supported exclusively ongrok-imagine-image-2.0, this parameter governs rendering refinement. When set toauto(the default), the API automatically selectslowfor text-to-image generation—ideal for rapid iteration and batch exploration—andmediumfor image editing tasks where preserving fine source details is critical. Passinglowormediumexplicitly pins the quality tier and corresponding billing rate.resolution(1k,2k): Controls the pixel density of the final output. Omitting this parameter defaults to1k, while specifying2kdelivers sharper textures for print, large displays, or detailed UI mockups.
Putting It Together in Code
Generating production-ready images with grok-imagine-image-2.0 takes only a few lines of code using either the native xai_sdk or an OpenAI-compatible client:
import os
from xai_sdk import Client
client = Client(api_key=os.getenv("XAI_API_KEY"))
response = client.image.sample(
model="grok-imagine-image-2.0",
prompt="Editorial architectural photograph of a glass pavilion in a misty redwood forest at dawn",
aspect_ratio="21:9",
resolution="2k",
quality="medium",
)
print(response.url)
For high-throughput workflows—such as generating up to n=10 variations per prompt or firing concurrent requests—you can also pass deferred: true on the REST endpoint to receive a request_id immediately, then poll GET /v1/images/{request_id} or listen for image.generation.completed webhooks without holding HTTP connections open.
Leave a Reply