Grok Imagine image generation (text or image input)

Generate images with xAI Grok Imagine through an OpenAI-compatible endpoint. Supports text-to-image (t2i) and image-to-image (i2i).

POST /v1/images/generations

## Grok Imagine image generation xAI Grok Imagine series image models, follows the standard OpenAI image interface `POST /v1/images/generations`, can be invoked using the OpenAI SDK 0 by simply modifying the code. **Model** - `grok-imagine-image` — Standard image generation - `grok-imagine-image-quality` — High-quality mode (higher resolution and detail) **Text-to-image (t2i)**: Only pass `prompt` **Image-to-image (i2i)**: Pass the `image` field additionally (reference image). ⚠️ `image` must be an object of type `{"url": "https://..."}`; **do not pass a bare string URL** (otherwise returns 400) Response in OpenAI-compatible format, image data in `data[].b64_json` (base64) or `data[].url`

Request body

modelstringrequiredImage model ID
promptstringrequiredText description, supports both Chinese and English; more specific descriptions lead to higher generation quality
nintegerNumber of generated images
sizestringImage dimensions (width × height)
qualitystringquality level; `grok-imagine-image-quality` high quality tier (higher resolution)
imageobjectimage-to-image (i2i) reference image. ⚠️ Must be an object `{"url": "https://..."}`, cannot pass bare string. Required only for image-to-image generation.

Responses

Example

# 文生图 (t2i)
curl https://api.router.ai/v1/images/generations \
  -H "Authorization: Bearer $YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "grok-imagine-image",
    "prompt": "赛博朋克风格的城市夜景, 霓虹与雨水倒影",
    "size": "1024x1024",
    "n": 1
  }'

# 图生图 (i2i) — image 必须是 {"url":...} 对象
curl https://api.router.ai/v1/images/generations \
  -H "Authorization: Bearer $YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "grok-imagine-image",
    "prompt": "把这张图改成水彩画风格",
    "image": { "url": "https://example.com/photo.jpg" }
  }'

API reference