Mastering the xAI Image Generation API: Aspect Ratios, Quality Tiers, and the Shift to Grok Imagine 2.0
Building visual pipelines with xAI’s /v1/images/generations endpoint gives developers granular control over framing, resolution, and rendering cost. However, if you are reading older integration guides or maintaining legacy codebases, you may run into parameters and model names that have evolved significantly.
A complete breakdown of how xAI handles aspect_ratio, the quality parameter, and the retirement of the grok-imagine-image-quality model slug reveals how to configure requests properly.
The Retirement of grok-imagine-image-quality
If your application still targets model="grok-imagine-image-quality", your API calls are running on a compatibility redirect.
Following a 60-day deprecation window, xAI officially retired the grok-imagine-image-quality model slug on November 2, 2026. Its capabilities—along with those of grok-imagine-image-pro—were consolidated into grok-imagine-image-2.0.
- Automatic Redirects: Any request sent to
/v1/images/generationsor/v1/images/editswithgrok-imagine-image-qualityis automatically routed togrok-imagine-image-2.0running withquality: "low". - Lower Costs: Migrating to or being redirected to
grok-imagine-image-2.0at low quality reduces generation costs by $0.01 per image across resolutions ($0.04 per 1K image and $0.06 per 2K image). - Expanded Capabilities: Updating your
modelstring togrok-imagine-image-2.0unlocks explicitqualitytier selection, multi-image editing (up to 5 reference images), and ultra-wide aspect ratios like21:9and5:2.
Controlling Generation Quality
Rather than forcing developers to switch between separate model slugs for speed versus fidelity, grok-imagine-image-2.0 uses an optional quality parameter on /v1/images/generations.
auto(Default): Lets the API select the optimal tier based on the endpoint. Currently,autodefaults tolowfor text-to-image generation andmediumfor image-to-image editing.low: Optimized for fast throughput and lower cost while maintaining high prompt adherence. This is the direct equivalent of the legacygrok-imagine-image-qualitymodel.medium: Allocates additional compute for finer textures, complex lighting, and higher detail density.
Note: You are billed strictly at the quality tier served, so pinning "low" or "medium" ensures predictable unit economics in production.
Mastering aspect_ratio Across Devices and Formats
Unlike APIs that limit you to basic square, portrait, and landscape crops, xAI’s image generation endpoint supports 15 distinct aspect ratios plus an intelligent auto mode. Notably, it includes native support for modern smartphone screen dimensions so mobile wallpapers and full-bleed UI assets don’t suffer from awkward OS cropping.
| Aspect Ratio | Orientation / Format | Primary Use Cases |
|---|---|---|
auto |
Dynamic (Default) | Lets the model infer the best framing from your prompt |
1:1 |
Square | Social media feeds, avatars, album art, thumbnails |
16:9 / 9:16 |
Standard Widescreen / Vertical | YouTube videos, desktop wallpapers, TikTok, Reels, Stories |
4:3 / 3:4 |
Classic Display / Portrait | Slide decks, tablets, editorial portraits |
3:2 / 2:3 |
35mm Film / DSLR | Traditional photography, print layouts |
2:1 / 1:2 |
Panoramic / Tall Banner | Web hero headers, vertical infographics |
19.5:9 / 9:19.5 |
Modern iPhone Display | Edge-to-edge iOS lock screens and full-bleed mobile apps |
20:9 / 9:20 |
Modern Android Display | Edge-to-edge Android wallpapers and mobile banners |
21:9 |
Cinematic Widescreen | Ultrawide monitors, anamorphic film frames (2.0 only) |
5:2 |
Ultra-Wide Banner | Leaderboard ads, wide storefront headers (2.0 only) |
When building multi-asset campaigns or storyboards, lock aspect_ratio explicitly rather than relying on auto so every generated frame shares identical geometry.
Implementation Example
Combining grok-imagine-image-2.0 with explicit aspect_ratio, resolution (1k or 2k), and quality parameters requires only a few lines of code using the official xAI Python SDK:
import xai_sdk
client = xai_sdk.Client()
# Generate a single 2K cinematic frame with explicit quality and ratio
response = client.image.sample(
model="grok-imagine-image-2.0",
prompt="A rain-slicked Tokyo alleyway at midnight, glowing neon kanji reflections, shot on 35mm anamorphic lens",
aspect_ratio="21:9",
resolution="2k",
quality="medium",
)
if response.respect_moderation:
print(f"Image URL: {response.url}")
For high-volume workflows, you can generate up to 10 variations in a single call using client.image.sample_batch(n=4, ...) or pass deferred=True on the REST endpoint (/v1/images/generations) to process long-running batches asynchronously via polling or webhooks.
Leave a Reply