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

  • Base URL: https://docs.x.ai (the document declares no server; this is the origin it was published from)
  • URL: https://docs.x.ai/v1/images/generations
  • Auth: HTTP bearer

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' | '21:9' | '5:2' | 'auto'

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

deferredboolean nullable

If set, the request returns immediately with a request_id and the image is generated in the background. Poll GET /v1/images/{request_id} for the result. Only response_format: "url" is supported in this mode.

modelstring nullable

Model to be used.

ninteger nullable

Number of images to be generated

promptstring

Prompt for image generation.

resolution'1k' | '2k' | '1.5k'

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

Changes

No recorded changes to this operation across all 1 revision of this API.