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`
model | string | required | Image model ID |
prompt | string | required | Text description, supports both Chinese and English; more specific descriptions lead to higher generation quality |
n | integer | Number of generated images | |
size | string | Image dimensions (width × height) | |
quality | string | quality level; `grok-imagine-image-quality` high quality tier (higher resolution) | |
image | object | image-to-image (i2i) reference image. ⚠️ Must be an object `{"url": "https://..."}`, cannot pass bare string. Required only for image-to-image generation. |
200 — successfully returns generated images (OpenAI-compatible)400 — invalid request parameters (e.g., image passed as bare string instead of {"url"} object)402 — Insufficient balance# 文生图 (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" }
}'