Grok Imagine Image API: Aspect Ratio Guide | xAI Docs

Written by

in

Framing the Canvas: How aspect_ratio Works with grok-imagine-image in xAI’s API

When you generate or edit images with xAI’s Grok Imagine image models (grok-imagine-image and grok-imagine-image-2.0) via /v1/images/generations and /v1/images/edits, composition starts with framing. The aspect_ratio parameter gives developers explicit control over canvas proportions—or lets the model decide automatically when you leave it open.

Why aspect_ratio Matters in Image Generation

A great prompt can still fall flat in the wrong frame. Wide widescreen landscapes (16:9 or 20:9), tall vertical stories (9:16 or 9:19.5), editorial portraits (3:4 or 2:3), and square thumbnails (1:1) each change how subjects are composed, cropped, and balanced.

In xAI’s image APIs:

  • aspect_ratio controls proportions directly on both image generation (/v1/images/generations) and image editing (/v1/images/edits) endpoints.
  • Omitting aspect_ratio defaults to "auto", allowing the model to select a ratio that fits the prompt’s subject and layout.
  • In image edits, the default behavior can follow the input image’s framing (or the first reference image in multi-image edits), while explicitly passing aspect_ratio overrides that target frame.

Common Ratios and When to Use Them

| Ratio | Orientation | Typical Use Cases |
| :— | :— | :— |
| 1:1 | Square | Avatars, product cards, feed tiles, symmetrical compositions |
| 16:9 / 20:9 | Landscape / Ultrawide | Hero banners, cinematic scenes, presentation backdrops |
| 9:16 / 9:19.5 / 9:20 | Portrait / Tall Mobile | Short-form vertical video covers, full-bleed mobile screens |
| 4:3 / 3:2 | Classic Landscape | Editorial photography, UI previews, balanced scenes |
| 3:4 / 2:3 | Classic Portrait | Book/poster layouts, character portraits, vertical editorial |
| auto | Adaptive | Prompts where you want the model to infer natural framing |

Practical Request Pattern

When calling xAI’s image generation endpoint directly with grok-imagine-image (or grok-imagine-image-2.0), pass aspect_ratio alongside model and prompt:

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",
    "prompt": "A serene coastal cliff at sunrise with low fog rolling over basalt columns, crisp architectural light",
    "aspect_ratio": "16:9"
  }'

Tips for Reliable Framing

  1. Lock the ratio for UI and layout slots: Whenever an image must fit a fixed container—like a 16:9 hero slot or 9:16 mobile card—specify aspect_ratio explicitly rather than relying on "auto".
  2. Align prompt cues with the chosen frame: Mentioning sweeping horizons in a narrow vertical frame or tight close-ups in an ultrawide frame creates tension; match camera/composition language to the ratio.
  3. Iterate fast before scaling up: When exploring concepts or generating multiple variations, test framing early so you don’t waste high-detail or multi-image runs on awkward crops.

Comments

Leave a Reply

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