xAI Image Generation API: Aspect Ratio & Quality Guide

Written by

in

Framing, Quality, and Model Migration in xAI’s Image Generation API

Developers building with xAI’s image generation endpoint (/v1/images/generations) now work with a unified, lower-cost stack centered on grok-imagine-image-2.0, while grok-imagine-image-quality has been retired as a standalone slug. Controlling framing through aspect_ratio and output fidelity through quality and resolution lets teams balance speed, visual polish, and per-image cost without changing request shapes.


What Happened to grok-imagine-image-quality?

Effective November 2, 2026 (following a 60-day notice that started September 2, 2026), xAI retired the grok-imagine-image-quality model slug.

  • Automatic routing: Requests sent to grok-imagine-image-quality (as well as grok-imagine-image-pro, which already pointed to it) are automatically served by grok-imagine-image-2.0 with quality: "low".
  • Backward-compatible payloads: Existing request and response shapes remain unchanged, so older integrations do not break immediately.
  • Lower pricing: Running grok-imagine-image-2.0 at low quality is $0.01 cheaper per image across resolutions than the retired grok-imagine-image-quality model ($0.04 per 1K image and $0.06 per 2K image, plus $0.01 per input image on edits).
  • How to verify migration: Inspect usage.cost_in_usd_ticks in API responses—or check the reported model name in gRPC responses via the xAI SDK, which surfaces as grok-imagine-image-2.0-low.

Switching your model parameter directly to "grok-imagine-image-2.0" is a one-line change that unlocks explicit quality control, up to five source images for editing, and expanded aspect ratios like 21:9 and 5:2.


Controlling Framing with aspect_ratio

The aspect_ratio parameter sets the target proportions of generated images on /v1/images/generations. When omitted, it defaults to "auto", allowing the model to pick a ratio suited to the prompt.

Aspect Ratio Typical Use Cases
1:1 Social media posts, square thumbnails
16:9 / 9:16 Widescreen video/layouts, mobile screens, vertical stories
4:3 / 3:4 Slide presentations, classic portraits
3:2 / 2:3 Standard photography framing
2:1 / 1:2 Banners, headers, tall vertical slots
19.5:9 / 9:19.5 Modern smartphone displays (iPhone)
20:9 / 9:20 Modern smartphone displays (Android)
21:9 Cinematic widescreen
5:2 Wide horizontal banners
auto Default; model chooses the best ratio for the prompt

For multi-image series or storyboards, locking aspect_ratio to a single value (such as "3:2" for photographic sets) keeps frames visually consistent across runs.


Balancing Fidelity with quality and resolution

Supported only on grok-imagine-image-2.0, the optional quality parameter accepts "low", "medium", or "auto":

  • "auto" (default): Lets xAI select the quality tier per request—currently defaulting to low for image generation and medium for image editing.
  • "low": Best for fast iteration, early concept exploration, and cost-sensitive batch runs; matches the behavior of the post-retirement grok-imagine-image-quality redirect.
  • "medium": Pins higher detail for final selects or polish passes.

Quality pairs with resolution ("1k" by default, or "2k" for higher pixel dimensions) and batch size n (1 to 10 images per request). Images are billed at the quality tier and resolution at which they are served.

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": "Architectural photograph of a glass conservatory in morning fog",
    "aspect_ratio": "3:2",
    "resolution": "2k",
    "quality": "medium",
    "n": 1
  }'

Practical Workflow Tips

  1. Draft cheap, finish sharp: Generate several variations at quality: "low" and resolution: "1k" to test composition and prompt wording, then regenerate winning prompts at quality: "medium" and resolution: "2k".
  2. Use deferred: true for heavy batches: Larger batches or long-running jobs can set "deferred": true to return a request_id immediately and poll GET /v1/images/{request_id} (or listen via webhooks such as image.generation.completed), with results retained for 24 hours when using response_format: "url".
  3. Separate distinct prompts with concurrency: When generating unrelated prompts rather than variations of one prompt, run parallel requests (such as AsyncClient with asyncio.gather in Python) instead of waiting on sequential calls.

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *