GPT Image 2 API
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
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.
route string optional Omit for the default route, or pass default explicitly.
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.
resolution enum optional Image output resolution.
- Auto aspect ratio
- Only 1K when aspect ratio is auto or unspecified
- 2K unavailable
- 4K unavailable
background enum optional The background parameter is supported only at 1K; omit this field for 2K/4K.
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.
when enum optional Callback trigger timing. Use final for terminal-state notifications.
The beta route resolves to the canonical model ID gpt-image-2/text-to-image@beta. A size field replaces aspect_ratio and resolution. Prefer the base model plus route: "beta" at the top level.
model string required Fixed value gpt-image-2/text-to-image, combined with route to select the beta route.
route string required Fixed value beta.
input object required Business parameters.
prompt string required Text prompt, up to 20000 characters.
size string optional Output size, replacing aspect_ratio and resolution. Use auto or lowercase-x widthxheight with 3–5 digits per dimension, such as 1024x1024.
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.
when enum optional Callback trigger timing. Use final for terminal-state notifications.
The HiAPI ext multi-ratio 4K route resolves to the canonical model ID gpt-image-2/text-to-image@ext. All 16 aspect ratios are available at 1K/2K/4K, and resolution and quality are required. Prefer route: "ext" at the top level.
model string required Fixed value gpt-image-2/text-to-image, combined with route to select the ext route.
route string required Fixed value ext.
input object required Business parameters.
prompt string required Text prompt, up to 20000 characters.
aspect_ratio enum optional Output aspect ratio; all 16 ratios are available at every resolution tier (including 5:4, 4:5, 2:1, etc.).
resolution enum required HiAPI ext route resolution tier: 1K, 2K, or 4K. Actual pixel dimensions vary by aspect ratio.
quality enum required Quality tier, affects pricing: low is clean and sharp for volume, medium adds visible detail, high is cinematic.
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.
when enum optional Callback trigger timing. Use final for terminal-state notifications.
Request example
Minimum usable request with prompt, aspect ratio, and resolution.
{
"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"
}
}When you need transparency, pass background=transparent with 1K resolution.
{
"model": "gpt-image-2/text-to-image",
"route": "beta",
"input": {
"prompt": "A clean product photo of a red apple on a white table",
"size": "1024x1024"
}
}For product pages, social avatars, and square cover placements.
{
"model": "gpt-image-2/text-to-image",
"route": "ext",
"input": {
"prompt": "A clean product photo of a red apple on a white table",
"aspect_ratio": "1:1",
"resolution": "1K",
"quality": "low"
}
}{
"code": 200,
"message": "success",
"data": {
"taskId": "tk-hiapi-..."
}
}Getting the result
- The response returns a taskId immediately without waiting for generation to finish.
- In production, prefer waiting for callback.url to receive the terminal notification. For local debugging, poll GET /v1/tasks/:id.
- When status=success, download the image from data.output[].url and retain it before expireAt.
- 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.