v4

latestOpenAPI 3.1.02026-08-0143190206.8 KB
v1

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

post/v1/images/generations

Request body

aspect_ratio'1:1' | '3:4' | '4:3' | '9:16' | '16:9' | '2:3' | '3:2' | '9:19.5' | '19.5:9' | '9:20' | '20:9' | '1:2' | '2:1' | 'auto'

Aspect ratio for image generation. Only supported by grok-imagine models.

modelstring nullable

Model to be used.

ninteger nullable

Number of images to be generated

promptstring

Prompt for image generation.

resolution'1k' | '2k'

Resolution for image generation. Only supported by grok-imagine models.

response_formatstring nullable

Response format to return the image in. Can be url or b64_json. If b64_json is specified, the image will be returned as a base64-encoded string instead of a url to the generated image file.

userstring nullable

A unique identifier representing your end-user, which can help xAI to monitor and detect abuse.

Example request

{
  "model": "grok-imagine-image"
}

Response

Success