Skip to main content
POST
Use this route to edit one or more images with Grok image models. The request body uses application/json.

Provide image input

  • Send exactly one of image or images.
  • Use image for one source image.
  • Use images for two or three source images.
  • In each image object, use url for a public URL or data URI. image_url is a compatibility alias for url.
  • Use aspect_ratio to control the output shape for multi-image edits.
Choose a Grok image model ID from the Models page. The API examples use grok-imagine-image-quality.
Send Grok image edit requests as JSON. Multipart form data does not represent this request shape.
The OpenAI SDK images.edit() method sends multipart form data. Use a direct HTTP request for Grok JSON image edits. For provider parameter details, see the xAI image editing guide.

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 instruction that describes the requested edit.

Minimum string length: 1
Example:

"Replace the daytime sky with a soft sunset and preserve the building"

image
object
required

One source image. Use this field instead of images.

images
object[]

Two or three source images. Use this field instead of image.

Required array length: 2 - 3 elements

A source image represented by url or the compatibility alias image_url.

n
integer
default:1

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

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

The output shape for a multi-image edit.

Available options:
1:1,
3:4,
4:3,
16:9,
2:3,
3:2,
9:19.5,
19.5:9,
9:20,
20:9,
1:2
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 edited image results.

data
object[]
required

The edited images.

Minimum array length: 1
usage
object
required

Usage details for the request.