Skip to content
English

GPT Image 2 API

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

Submit a text-to-image or image-to-image task, then query it with GET /v1/tasks/:id.

Send model=gpt-image-2/text-to-image to POST /v1/tasks to call GPT Image 2. This reference covers every request field, route difference, callback, polling step, and code example.

Request parameters

Route

Default route. Its canonical model ID is gpt-image-2/text-to-image. It supports 1K/2K/4K and 16 aspect ratios (including auto); price varies by resolution.

model string required

Fixed value gpt-image-2/text-to-image.

example gpt-image-2/text-to-image
route string optional

Omit for the default route, or pass default explicitly.

example default
input object required

Business parameters. GPT Image 2 model-specific configuration lives here.

prompt string required

Text prompt, up to 20000 characters.

aspect_ratio enum optional

Aspect ratio of the generated image. Default auto.

default auto enum: auto1:13:22:34:33:45:44:516:99:16 +6
resolution enum optional

Image output resolution.

Auto aspect ratio
Only 1K when aspect ratio is auto or unspecified
2K unavailable
5:44:53:11:39:21
4K unavailable
1:13:11:39:21
default 1K enum: 1K2K4K
background enum optional

The background parameter is supported only at 1K; omit this field for 2K/4K.

enum: autoopaquetransparent
callback object optional

Optional callback configuration. HiAPI sends a terminal notification to your service when the task finishes.

url string required

Required when callback is provided. HTTPS URL that receives the terminal task notification.

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

Callback trigger timing. Use final for terminal-state notifications.

default final enum: final

Request example

Basic text-to-image

Minimum usable request with prompt, aspect ratio, and resolution.

Request body
{
  "model": "gpt-image-2/text-to-image",
  "input": {
    "prompt": "A red apple isolated on a transparent background.",
    "aspect_ratio": "1:1",
    "resolution": "1K",
    "background": "transparent"
  },
  "callback": {
    "url": "https://your-domain.com/hiapi/callback",
    "when": "final"
  }
}
Success response

Response body
{
  "code": 200,
  "message": "success",
  "data": {
    "taskId": "tk-hiapi-..."
  }
}

Getting the result

  1. The response returns a taskId immediately without waiting for generation to finish.
  2. In production, prefer waiting for callback.url to receive the terminal notification. For local debugging, poll GET /v1/tasks/:id.
  3. When status=success, download the image from data.output[].url and retain it before expireAt.
  4. For a synchronous 4xx response from POST, fix authentication, balance, or request-schema errors. For status=fail while retrieving the task, log data.error and do not blindly retry the same invalid request.