Generate 2:1 Images with xAI Grok-Imagine API

Written by

in

Framing Wide Banners with grok-imagine-image and aspect_ratio: "2:1"

xAI’s image generation API lets you specify proportional framing directly through the aspect_ratio parameter rather than hardcoding pixel dimensions. Setting aspect_ratio to "2:1" with a Grok image model such as grok-imagine-image-2.0 produces a wide 2-to-1 horizontal canvas tailored for web banners, article headers, and wide hero layouts.

Why 2:1 Works for Banners and Headers

A 2:1 aspect ratio gives you double the width of its height, creating horizontal breathing room without stretching into ultra-panoramic ratios like 21:9 or 5:2. According to the xAI image generation documentation:

  • Primary fit: Banners and headers (2:1), paired with vertical 1:2 when you need a tall counterpart.
  • Alternative framing: If you omit aspect_ratio, it defaults to auto, allowing the model to choose a ratio based on the prompt. Other supported options include 1:1, 16:9 / 9:16, 4:3 / 3:4, 3:2 / 2:3, 19.5:9 / 9:19.5, 20:9 / 9:20, 21:9, and 5:2.
  • Decoupled scale and quality: Shape (aspect_ratio) is separate from pixel scale (resolution, such as 1k or 2k) and quality (low, medium, or auto on grok-imagine-image-2.0), while batch size is controlled with n (1–10).

Calling /v1/images/generations with 2:1

Whether you use the xAI Python SDK, an OpenAI-compatible client pointed at [https://api.x.ai/v1](https://api.x.ai/v1), or the Vercel AI SDK, you pass the model name, prompt, and 2:1 ratio to generate images.

import xai_sdk

client = xai_sdk.Client()
response = client.image.sample(
    prompt="Minimalist architectural studio overlooking coastal cliffs at dawn",
    model="grok-imagine-image-2.0",
    aspect_ratio="2:1",
)
print(response.url)

For batch generations or heavier workloads on /v1/images/generations, you can request multiple images via n (up to 10), choose url (the default for response_format) or base64, or use deferred: true for long-running batches and poll GET /v1/images/{request_id} or subscribe to image generation webhook events.

Practical Tips for 2:1 Prompts

  1. Compose horizontally: Describe wide foreground-to-background depth, split scenes, or left-to-right movement so the 2:1 frame feels intentional rather than cropped.
  2. Leave negative space if needed: If text or UI overlays will sit on top of a banner or header, ask for clean sky, wall, or background space on one side.
  3. Explore fast, then refine: Use n to preview several 2:1 compositions in one call before locking in your preferred direction.

Comments

Leave a Reply

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