Skip to main content
POST
Use this route to create images from text with Grok image models. The request body uses application/json. The request supports model, prompt, n, aspect_ratio, resolution, and response_format.

Choose a model

Choose a Grok image model ID from the Models page. The API examples use grok-imagine-image-quality.

Configure the output

  • Use aspect_ratio to select the output shape, or use auto to let the model select the shape.
  • Use resolution to request 1k or 2k output.
  • Use n to request up to 10 images.
  • Use response_format to return temporary URLs or Base64-encoded image data.
For provider parameter details, see the xAI image generation guide.
Download URL results after the request completes. Generated image URLs can expire.

Authorizations

Authorization
string
header
required

Use your CometAPI API key as the bearer value.

Body

application/json
model
enum<string>
required

The Grok image model ID. See the Models page for available model IDs.

Available options:
grok-imagine-image,
grok-imagine-image-quality
Example:

"grok-imagine-image-quality"

prompt
string
required

A text description of the image to generate.

Minimum string length: 1
Example:

"A glass observatory above a quiet alpine lake at sunrise"

n
integer
default:1

The number of images to generate. Use an integer from 1 through 10.

Required range: 1 <= x <= 10
aspect_ratio
enum<string>

The output shape. Use auto to let the model select the aspect ratio.

Available options:
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
Example:

"16:9"

resolution
enum<string>

The requested output resolution.

Available options:
1k,
2k
Example:

"1k"

response_format
enum<string>
default:url

The image representation in each response item. Use url for a temporary download URL or b64_json for Base64-encoded image bytes.

Available options:
url,
b64_json

Response

200 - application/json

The generated image results.

data
object[]
required

The generated images.

Minimum array length: 1
usage
object
required

Usage details for the request.