Skip to main content
POST
Use this route to create images from text with Grok image models. The request body uses application/json. model and prompt are required.

Choose a model

Choose a Grok image model ID from the Models page. The API examples use grok-imagine-image-2.0. quality is available only with grok-imagine-image-2.0 and accepts low or medium. Set it explicitly when your application depends on a particular quality level. When resolution is omitted for Image 2.0, CometAPI uses 1k.

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 from 1 through 10 images. The default is 1.
  • Use response_format to return temporary URLs or Base64-encoded image data.
For model-specific behavior, see the xAI image generation guide.
Download URL results promptly after the request completes. Generated image URLs are temporary. Use b64_json when your application needs the image bytes in the API response.

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,
grok-imagine-image-2.0
Example:

"grok-imagine-image-2.0"

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>
default:1k

The requested output resolution. Image 2.0 uses 1k when this field is omitted.

Available options:
1k,
2k
Example:

"1k"

quality
enum<string>

Image quality for grok-imagine-image-2.0. This field is not available for the older Grok image model IDs.

Available options:
low,
medium
Example:

"low"

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

Additional usage metadata returned for the request. Its contents can vary by model.

Last modified on August 21, 2026