Skip to main content

Grok Image Models

POST /v1/images/generations
Grok image models use the OpenAI-compatible Images path. There are two names you should treat differently:
ModelDescriptionRecommendation
grok-imagine-imageOfficial xAI image model name, billed at the official $0.02 / image priceRecommended for new integrations
grok-4-imageHistorical / compatibility model name on third-party compatible channelsUse only the safe subset of parameters
grok-4-image is not the official xAI model name. Do not assume it is fully equivalent to grok-imagine-image. New integrations should prefer grok-imagine-image.

grok-imagine-image Parameters

ParameterTypeRequiredDescription
modelstringYesUse grok-imagine-image
promptstringYesImage prompt
nintegerNoNumber of images, official range 1 to 10. Use 1 first for stable cost control
response_formatstringNourl or b64_json. The live Crazyrouter path is stable with url
aspect_ratiostringNoExamples: 1:1, 16:9, 9:16, 3:2, auto
resolutionstringNo1k or 2k
aspect_ratio and resolution are xAI image endpoint extensions. With the OpenAI Python SDK, pass them through extra_body; with cURL or the Node.js SDK, put them directly in the JSON body.
Do not pass these parameters:
ParameterReason
sizeNot supported by xAI; it returns Argument not supported: size
qualityNot supported by the xAI image endpoint
styleNot supported by the xAI image endpoint

grok-imagine-image Example

curl -X POST https://crazyrouter.com/v1/images/generations \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -d '{
    "model": "grok-imagine-image",
    "prompt": "A tiny yellow cube on a plain white background, minimal product photo",
    "n": 1,
    "response_format": "url",
    "aspect_ratio": "1:1",
    "resolution": "1k"
  }'

Response Example

The live response may include url, mime_type, and revised_prompt:
{
  "created": 1776527939,
  "data": [
    {
      "url": "https://...",
      "mime_type": "image/jpeg",
      "revised_prompt": "A tiny yellow cube on a plain white background..."
    }
  ]
}

grok-4-image Differences

Use only this safe subset for grok-4-image:
ParameterSupport
modelUse grok-4-image
promptSupported
nUse 1 only. A live n=2 test returned 1 image but billed 2 images; the gateway has been narrowed to 1
response_formaturl is stable. b64_json may be accepted but the live route still returned url
aspect_ratioAccepted by the request path, but third-party enforcement should be verified per output
resolutionAccepted by the request path, but third-party enforcement should be verified per output
Do not promise these for grok-4-image:
  • multi-image n > 1
  • guaranteed b64_json output
  • size
  • quality
  • style
  • image editing

grok-4-image Example

curl -X POST https://crazyrouter.com/v1/images/generations \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -d '{
    "model": "grok-4-image",
    "prompt": "A single red cube on a plain white background, product photo",
    "n": 1,
    "response_format": "url"
  }'

Billing

ModelCurrent Billing
grok-imagine-image$0.02 / image, no discount
grok-4-imageCurrent pricing is $0.08 * 0.55 = $0.044 / image
The live pricing page and usage logs are the source of truth. Grok image models are billed per image, not by input/output tokens.

Common Errors

ErrorFix
Argument not supported: sizeDo not send size; use aspect_ratio and resolution
model_price_errorThe model is missing pricing or the token cannot use it
model_not_foundCheck the model name, token permissions, and channel availability with GET /v1/models