AIAPIAIAPI API

Grok Imagine Image 2.0 Edit

Model ID xai/grok-imagine-image-2.0/edit

Overview

Image editing from 1 to 5 source images with natural-language instructions.

xAI · image-to-image

Endpoint

POST /v1/images/generations/async

Authentication

Authorization: Bearer <AIAPIAIAPI_API_KEY>

Request Body

ParameterTypeRequiredNullableDefaultConstraintsDescription
modelstringYesNo-values: xai/grok-imagine-image-2.0/editModel ID used to route the request.
promptstringYesNo--Image generation or editing prompt, up to 8000 characters.
imagesarrayYesNo-min_items: 1; max_count: 5; accepts: URL, Base64 data URLSource images. Refer to them as <IMAGE_0> through <IMAGE_4> in the prompt. Input images are charged by the provider separately from outputs.
resolutionstringNoNo`1k`values: 1k, 2kOutput image resolution.
aspect_ratiostringNoNo`auto`values: auto, 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:1auto lets the model choose; output generally follows the first source image's aspect ratio.
nintegerNoNo`1`range: 1-4Number of output images. Each image is billed separately.
qualitystringNoNo`medium`values: low, mediumImage rendering quality tier.

model

Type: string · Required: Yes · Nullable: No

Model ID used to route the request.

prompt

Type: string · Required: Yes · Nullable: No

Image generation or editing prompt, up to 8000 characters.

images

Type: array · Required: Yes · Nullable: No

Source images. Refer to them as <IMAGE_0> through <IMAGE_4> in the prompt. Input images are charged by the provider separately from outputs.

resolution

Type: string · Required: No · Nullable: No

Output image resolution.

aspect_ratio

Type: string · Required: No · Nullable: No

auto lets the model choose; output generally follows the first source image's aspect ratio.

n

Type: integer · Required: No · Nullable: No

Number of output images. Each image is billed separately.

quality

Type: string · Required: No · Nullable: No

Image rendering quality tier.

Request Example

curl --request POST \
  --url https://aiapiaiapi.com/v1/images/generations/async \
  --header 'Authorization: Bearer $AIAPIAIAPI_API_KEY' \
  --header 'Content-Type: application/json' \
  --data '{
      "model": "xai/grok-imagine-image-2.0/edit",
      "prompt": "A cinematic camera movement through a forest",
      "images": ["https://example.com/reference.jpg"],
      "resolution": "1k"
    }'

JSON

{
  "model": "xai/grok-imagine-image-2.0/edit",
  "prompt": "A cinematic camera movement through a forest",
  "images": ["https://example.com/reference.jpg"],
  "resolution": "1k"
}

Response

{
  "code": "success",
  "message": "",
  "data": { "task_id": "image_01K2ABC123" }
}

Task Status

Use the task_id from the create response:

GET /v1/images/generations/async/{task_id}

{
  "code": "success",
  "message": "",
  "data": {
    "task_id": "image_01K2ABC123",
    "status": "SUCCESS",
    "progress": "100%",
    "outputs": ["https://cdn.example.com/images/image_01K2ABC123.png"],
    "start_time": 1786960805,
    "finish_time": 1786960900,
    "submit_time": 1786960800,
    "fail_reason": ""
  }
}

Error Responses

Validation errors return HTTP 400 with a stable error code.

{
  "code": "unsupported_parameter",
  "message": "The parameter is not supported by this model.",
  "data": null
}

Documentation Index

Fetch the complete documentation index at:

https://aiapiaiapi.com/llms.txt

Use this file to discover all available API documentation.