Inference API

Images

View as Markdown

Image generation

/v1/images/generations

Generate an image based on a prompt. This is the endpoint for making generation requests to image generation models.

Request Body

Response Body

dataarray<object>

A list of generated image objects.

Code Examples

**Response example:**


Example
curl -s https://api.x.ai/v1/images/generations \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $XAI_API_KEY" \
  -d '{
    "model": "grok-imagine-image-2.0",
    "prompt": "A collage of London landmarks in a stenciled street‑art style"
  }'
Exampletext

text

{
  "data": [
    {
      "url": "https://imgen.x.ai/xai-imgen/xai-tmp-imgen-a73bae6f-5a65-4bec-9ffb-8220caa3fa61.jpeg",
      "mime_type": "image/jpeg",
      "revised_prompt": ""
    }
  ],
  "usage": {
    "cost_in_usd_ticks": 200000000
  }
}

Image edit

/v1/images/edits

Edit an image based on a prompt. This is the endpoint for making edit requests to image generation models.

Request Body

promptstring

Prompt for image editing.

Response Body

dataarray<object>

A list of generated image objects.

Code Examples

**Response example:**

Example
curl -s https://api.x.ai/v1/images/edits \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $XAI_API_KEY" \
  -d '{
    "model": "grok-imagine-image-2.0",
    "prompt": "Render this as a pencil sketch with detailed shading",
    "image": {
      "url": "https://docs.x.ai/assets/api-examples/images/style-realistic.png",
      "type": "image_url"
    }
  }'
Exampletext

text

{
  "data": [
    {
      "url": "https://imgen.x.ai/xai-imgen/xai-tmp-imgen-82f06097-a9ad-4db4-9c8d-8197c74eebd1.jpeg",
      "mime_type": "image/jpeg",
      "revised_prompt": ""
    }
  ],
  "usage": {
    "cost_in_usd_ticks": 220000000
  }
}

Last updated:April 13, 2026