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

Changes

Changed in 2 of the 9 revisions of this API.7

    • added the new 21:9 enum value to the request property aspect_ratio/oneOf[ImageAspectRatio]/

      request-property-enum-value-added

    • added the new 5:2 enum value to the request property aspect_ratio/oneOf[ImageAspectRatio]/

      request-property-enum-value-added

    • added the optional property usage/oneOf[MediaUsage]/input_tokens to the response with the 200 status

      response-optional-property-added

    • added the optional property usage/oneOf[MediaUsage]/input_tokens_details to the response with the 200 status

      response-optional-property-added

    • added the optional property usage/oneOf[MediaUsage]/output_tokens to the response with the 200 status

      response-optional-property-added

    • added the optional property usage/oneOf[MediaUsage]/output_tokens_details to the response with the 200 status

      response-optional-property-added

    • added the optional property usage/oneOf[MediaUsage]/total_tokens to the response with the 200 status

      response-optional-property-added