Xai grok imagine image generations api aspect_ratio 50:11 site:docs.x.ai

Written by

in

Understanding aspect_ratio in xAI’s Grok Imagine Image Generations API

xAI’s image generation endpoint (/v1/images/generations), powered by models such as grok-imagine-image-2.0, lets developers generate images from text prompts with controls for batch size (n), resolution (1k or 2k), output format (url or base64), quality, and framing via the aspect_ratio parameter.

When aspect_ratio is omitted, the API defaults to "auto", allowing the model to select a ratio suited to the prompt. When you specify a ratio explicitly—such as "16:9", "4:3", "1:1", or ultrawide ratios like "20:9"—you constrain the canvas geometry before generation occurs.

What About 50:11?

A 50:11 ratio (roughly 4.55:1) represents an extreme panoramic or banner-style proportion—much wider than standard widescreen (16:9 is ~1.78:1) or even cinemascope and ultrawide formats (20:9 is ~2.22:1).

In practice, image generation APIs validate aspect_ratio against a supported set of ratio strings or presets rather than accepting arbitrary integer ratios. Even when third-party wrappers or docs list ultrawide options like 20:9 or 2:1, unusual custom ratios like 50:11 are not standard presets and can trigger validation errors or fall back depending on the SDK or gateway.

Designing for Extreme Panoramic & Banner Layouts

If your application needs a 50:11 visual—for example, a wide architectural frieze, timeline strip, or multi-panel header—generating directly at an extreme aspect ratio often stretches composition or clips subjects at the edges. A more reliable workflow is:

  1. Generate at a supported wide or panoramic ratio: Request a supported wide ratio (such as "16:9" or "20:9") at 2k resolution using grok-imagine-image-2.0 so you have ample pixel detail.
  2. Compose or crop deterministically in post-processing: Crop or stitch the generated asset to exact 50:11 pixel dimensions in your image pipeline where layout math is exact.
  3. Iterate with editing if needed: Use /v1/images/edits with grok-imagine-image-2.0 when you want to refine or extend visual elements while preserving core subjects.

Example Request (grok-imagine-image-2.0)

Using the REST or OpenAI-compatible client against [https://api.x.ai/v1](https://api.x.ai/v1), you pass model, prompt, and framing options such as aspect_ratio and resolution:

import os
from openai import OpenAI

client = OpenAI(
    api_key=os.environ["XAI_API_KEY"],
    base_url="https://api.x.ai/v1",
)

response = client.images.generate(
    model="grok-imagine-image-2.0",
    prompt="Panoramic view of a coastal cliffside town at golden hour, crisp architectural detail",
    aspect_ratio="16:9",
    response_format="url",
)

print(response.data[0].url)

For production pipelines, check the official docs.x.ai image generation reference for the exact supported aspect_ratio enum values and parameter options on your target model version, and handle invalid-parameter responses gracefully so your app can fall back to a supported ratio or "auto".

Comments

Leave a Reply

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