Skip to content
English

Grok Image 2.0 Image to Image API

POST Base URL: https://api.hiapi.ai /v1/tasks

Image, video, and audio models are called through the Unified Async API POST /v1/tasks endpoint; only the input fields differ (see input parameters below).

Model summary

Model name grok-imagine-image-2.0/image-to-image
Type Image generation (image-to-image)
Endpoint POST /v1/tasks
Pricing See HiAPI live pricing

xAI Grok Imagine Image 2.0 edits one public reference image with natural-language instructions for recoloring, restyling, scene changes, and refinements.

Production guidance

Production guidance
  • Pass one publicly reachable JPG, JPEG, PNG, or WebP URL in input.image; do not send an image_urls array.
  • Keep the API key on your server and use callback.url when your service should receive terminal task notifications.
  • aspect_ratio is accepted by the request validator but ignored during editing; the reference image determines the output framing.

Best suited for

Product-image changes

Preserve the subject while changing color, material, background, or lighting.

input.imageinput.prompt
Style transfer

Turn a reference photo into an illustration, cinematic frame, or another specified visual style.

input.imageinput.prompt
Single-image refinement

Drive a complete edit from one reference image and a natural-language instruction.

input.imageinput.qualityinput.resolution

Request parameters

model string required

Use grok-imagine-image-2.0/image-to-image.

example grok-imagine-image-2.0/image-to-image
input object required

Model input parameters.

prompt string required

Natural-language editing instruction for the reference image.

image string required

One public JPG, JPEG, PNG, or WebP reference image; the public contract accepts one image.

example https://static.hiapi.ai/example/inputs/sneaker.jpg
quality enum optional

Generation quality; medium has more detail and low has lower latency.

default medium enum: lowmedium
resolution enum optional

Output resolution tier.

default 1k enum: 1k2k
aspect_ratio enum optional

Accepted by the request contract, but ignored by the upstream editor; the reference image controls the result framing.

default 1:1 enum: 1:116:99:164:33:43:22:32:11:219.5:9 +4
callback object optional

Optional callback configuration for terminal task notifications.

url string required

HTTPS endpoint required when callback is provided.

example https://your-domain.com/hiapi/callback
when enum optional

Callback timing; use final.

default final enum: final

Example requests

Product recolor

Keep the sneaker shape, recolor it electric blue, and render a 2k studio shot.

Request body
{
  "model": "grok-imagine-image-2.0/image-to-image",
  "input": {
    "prompt": "Recolor the sneaker to vivid electric blue, keep the original shape and place it in a clean studio product shot",
    "image": "https://static.hiapi.ai/example/inputs/sneaker.jpg",
    "quality": "medium",
    "resolution": "2k",
    "aspect_ratio": "1:1"
  }
}
中文参考图编辑

使用中文指令编辑一张公开参考图。

Request body
{
  "model": "grok-imagine-image-2.0/image-to-image",
  "input": {
    "prompt": "把鞋子改成鲜艳的电光蓝,保持原有形状,并放在干净的棚拍产品画面中",
    "image": "https://static.hiapi.ai/example/inputs/sneaker.jpg",
    "quality": "medium",
    "resolution": "2k",
    "aspect_ratio": "1:1"
  }
}

Getting the result

  1. The response returns a taskId immediately.
  2. Poll GET /v1/tasks/:id or wait for the callback terminal event.
  3. When status=success, download the edited image from output[].url.
  4. When status=fail, fix the request using the returned error before retrying.

FAQ

Which image field should I send?

Send one publicly reachable JPG, JPEG, PNG, or WebP URL in input.image. Do not use an image_urls array.

Can I send multiple reference images?

No. The public Grok Image 2.0 image-to-image contract accepts one reference image.

Does aspect_ratio affect editing?

The field is accepted, but the upstream editor ignores it and follows the reference image framing.

How do I retrieve the edited image?

Read the returned taskId, poll GET /v1/tasks/:id or wait for callback.url, then download output[].url when status is success.

Next steps