Skip to content

Image Generation

Overview

  • Method: POST
  • Path: /v1/images/generations
  • Content-Type: application/json

Authentication

  • Authorization: Bearer sk-xxx (required)

Request Example

HeaderExampleRequired
Content-Typeapplication/jsonYes
AuthorizationBearer sk-xxxxYes

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

ParameterTypeRequiredDefaultDescription
promptstringYes-Image prompt text, max 1000 (4000) chars
modelstringYes-Model name, e.g. grok-2-image-1212
nnumberNo1Number of images (dall-e-2 supports 1-10, dall-e-3 supports 1 only)
response_formatstringNourlReturn 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..."
    }
  ]
}