Skip to content
English

Grok Image 2.0 Text 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/text-to-image
Type Image generation (text-to-image)
Endpoint POST /v1/tasks
Pricing See HiAPI live pricing

xAI Grok Imagine Image 2.0 for natural-language image generation with 1k/2k output and flexible square-to-ultrawide framing.

Production guidance

Production guidance
  • Keep the API key on your server. The unified task endpoint returns a taskId instead of holding the request open.
  • Pass callback.url at the top level when you want HiAPI to notify your service on success or failure.
  • The public contract supports only low/medium quality and 1k/2k resolution; unsupported values are rejected.

Best suited for

Fast visual ideation

Generate concept art, social assets, and product directions from natural-language prompts.

input.promptinput.quality
Banners and wide layouts

Use 16:9, 2:1, 19.5:9, or 20:9 for wide creative assets.

input.aspect_ratio
Selectable output size

Choose 1k for lower latency or 2k for more detail.

input.resolution

Request parameters

model string required

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

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

Model input parameters.

prompt string required

Description of the image to generate.

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

Output aspect ratio.

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

Cinematic product concept

Generate a wide product concept at 2k.

Request body
{
  "model": "grok-imagine-image-2.0/text-to-image",
  "input": {
    "prompt": "A premium editorial product photograph of a translucent glass camera aperture glowing over a dark studio surface",
    "quality": "medium",
    "resolution": "2k",
    "aspect_ratio": "16:9"
  }
}
Chinese product concept

Use a Chinese prompt for a landscape concept image.

Request body
{
  "model": "grok-imagine-image-2.0/text-to-image",
  "input": {
    "prompt": "深色摄影棚中的半透明玻璃光圈,内部发出洋红色光芒,高级商业产品摄影质感",
    "quality": "medium",
    "resolution": "2k",
    "aspect_ratio": "16:9"
  }
}

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 image from output[].url.
  4. When status=fail, fix the request using the returned error before retrying.

FAQ

What is the model ID?

Set model to grok-imagine-image-2.0/text-to-image.

Which quality and resolution values are supported?

quality supports low and medium; resolution supports 1k and 2k. The defaults are medium and 1k.

Which aspect ratios are supported?

The model accepts 1:1, 16:9, 9:16, 4:3, 3:4, 3:2, 2:3, 2:1, 1:2, 19.5:9, 9:19.5, 20:9, 9:20, and auto.

How do I retrieve the result?

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

Next steps