Image Generation
Overview
- Method:
POST - Path:
/v1/images/generations - Content-Type:
application/json
Authentication
Authorization: Bearer sk-xxx(required)
Request Example
Header
| Header | Example | Required |
|---|---|---|
| Content-Type | application/json | Yes |
| Authorization | Bearer sk-xxxx | Yes |
Request Body (JSON)
json
{
"model": "grok-2-image-1212",
"prompt": "A detailed image describing a vast Stone Age city...",
"n": 1,
"response_format": "url"
}Parameter Description
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
| prompt | string | Yes | - | Image prompt text, max 1000 (4000) chars |
| model | string | Yes | - | Model name, e.g. grok-2-image-1212 |
| n | number | No | 1 | Number of images (dall-e-2 supports 1-10, dall-e-3 supports 1 only) |
| response_format | string | No | url | Return format, url or b64_json |
Response Example (200)
json
{
"data": [
{
"url": "https://imgen.x.ai/xai-imgen/xai-tmp-imgen-11b443c1-3780-4690-849a-51430eecc0a9.jpeg",
"revised_prompt": "A high-resolution photograph of a bustling prehistoric city during the day..."
}
]
}