Skip to main content
xai avatar

Grok Imagine Image API

xai/grok-imagine/image

Generate high-quality images from a text prompt, with aspect-ratio control and a standard or high-resolution (2k) output.

0.02

Model Input

Input

Text description of the desired image.

Aspect ratio (width:height) of the generated image.

Additional Settings

Customize your input with more control.

Min: 1 - Max: 4

The number of images to generate. Each generated image is billed.

Output resolution tier: 1k (standard) or 2k (high resolution).

The image file format of the output.

You need to be logged in to run this model and view results.
Log in

Model Output

Output

Generated image output
Generated in 10.428 seconds
Logs (1 lines)

Model Example Requests

Examples

Example output 1Example output 2Example output 3Example output 4

Grok Imagine Image API

Grok Imagine Image is a text-to-image AI model by xai. On ModelRunner it runs through a REST API or via MCP from any AI assistant, at $0.02 per image.

POST https://queue.modelrunner.run/xai/grok-imagine/image

cURL

# Submit a request to the queue
curl -X POST https://queue.modelrunner.run/xai/grok-imagine/image \
  -H "Authorization: Key $MRUN_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "input": {
      "prompt": "isometric 3D illustration of a cozy independent bookshop interior at dusk, warm lamplight spilling over tall wooden s…",
      "num_images": 1,
      "resolution": "1k",
      "aspect_ratio": "9:16",
      "output_format": "png"
    }
  }'
# → { "request_id": "...", "status_url": "...", "response_url": "..." }

# Poll status_url until "COMPLETED", then fetch the result
curl "https://queue.modelrunner.run/xai/grok-imagine/image/requests/$REQUEST_ID/status" \
  -H "Authorization: Key $MRUN_API_KEY"
curl "https://queue.modelrunner.run/xai/grok-imagine/image/requests/$REQUEST_ID" \
  -H "Authorization: Key $MRUN_API_KEY"

JavaScript

import { modelrunner } from "@modelrunner/client";

const result = await modelrunner.subscribe("xai/grok-imagine/image", {
  input: {
    "prompt": "isometric 3D illustration of a cozy independent bookshop interior at dusk, warm lamplight spilling over tall wooden s…",
    "num_images": 1,
    "resolution": "1k",
    "aspect_ratio": "9:16",
    "output_format": "png"
  },
});
console.log(result);

Python

import os
import requests

headers = {"Authorization": f"Key {os.environ['MRUN_API_KEY']}"}

submitted = requests.post(
    "https://queue.modelrunner.run/xai/grok-imagine/image",
    headers=headers,
    json={"input": {
      "prompt": "isometric 3D illustration of a cozy independent bookshop interior at dusk, warm lamplight spilling over tall wooden s…",
      "num_images": 1,
      "resolution": "1k",
      "aspect_ratio": "9:16",
      "output_format": "png"
    }},
).json()

# Poll submitted["status_url"] until "COMPLETED", then:
result = requests.get(submitted["response_url"], headers=headers).json()

Input parameters

NameTypeRequiredDescription
promptstringyesText description of the desired image.
aspect_ratioenumnoAspect ratio (width:height) of the generated image. Default: "1:1".
num_imagesintegernoThe number of images to generate. Each generated image is billed. Default: 1.
resolutionenumnoOutput resolution tier: 1k (standard) or 2k (high resolution). Default: "1k".
output_formatenumnoThe image file format of the output. Default: "jpeg".

Machine-readable: OpenAPI schema · llms.txt

Use Grok Imagine Image from Claude & Cursor (MCP)

Point Claude Code, Claude Desktop, Cursor, or any MCP client at the ModelRunner MCP server and Grok Imagine Image becomes a tool your assistant can call directly — it authorizes via OAuth (no API key in config) and runs this model with the run_model tool using the endpoint xai/grok-imagine/image.

MCP client config (Claude Desktop, Cursor)

{
  "mcpServers": {
    "modelrunner": {
      "command": "npx",
      "args": ["-y", "mcp-remote", "https://mcp.modelrunner.run/mcp"]
    }
  }
}

Claude Code

claude mcp add --transport http modelrunner https://mcp.modelrunner.run/mcp

Then ask your assistant, for example: “Run xai/grok-imagine/image on ModelRunner to generate image”. MCP setup guide.

Model Details

Model Details

Grok Imagine Image generates high-quality images from a text prompt. Describe the scene, style, subject, and composition in natural language and it returns one to four rendered images. It handles photorealistic scenes, illustration, and stylized art, follows detailed multi-part prompts, and lets you pick the framing (aspect ratio) and a standard or high-resolution output. Put any text you want rendered inside the image in the prompt.

## Best for - Turning a written description into a finished image (concept art, product mockups, marketing visuals) - Photorealistic scenes and portraits from a detailed prompt - Illustration, digital painting, and stylized art directed entirely by text - Generating several variations of one idea in a single request (`num_images` up to 4) - Wide, tall, or square social and banner formats via the aspect-ratio presets

## Choose another model when - You want to modify or restyle an existing image rather than create one from scratch — use an image-editing model - You need to animate a prompt or a still into motion — use a text-to-video or image-to-video model - You need vector/SVG output rather than a raster image — use a vectorization model

## Tips - Be specific about subject, setting, lighting, and style; longer, structured prompts follow more reliably - Choose `aspect_ratio` to match the target format (e.g. `16:9` for banners, `9:16` for stories, `1:1` for avatars) - Set `resolution` to `2k` when you need extra detail for print or large displays; `1k` is the faster standard tier - Raise `num_images` to compare several takes at once — each generated image is billed

## Advanced Configuration - `output_format` selects the file type: `jpeg` (default, smallest), `png` (lossless), or `webp` (compact with transparency support).

To run via the ModelRunner JavaScript client: ```js import { modelrunner } from "@modelrunner/client";

const result = await modelrunner.subscribe("xai/grok-imagine/image", { input: { prompt: "a red vintage bicycle leaning against a pastel blue wall, soft morning light", aspect_ratio: "16:9", resolution: "1k", num_images: 1, }, }); ```