Skip to content
English

GPT Image 2 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 gpt-image-2/text-to-image
Type Image generation (text-to-image)
Routes default / beta / ext
Endpoint POST /v1/tasks
Model & Playground GPT Image 2 model page
Pricing guide GPT Image 2 API pricing and cost per image

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.

Production guidance

Production guidance
  • For production, pass callback.url at the top level of the request body so HiAPI can notify your service when the task reaches a terminal state.
  • GET /v1/tasks/:id is better for local debugging, low-volume jobs, or fallback reconciliation if a callback is missed.
  • Use callback.when=final. Both success and fail are terminal states, so your service should deduplicate by taskId.
API key and pricing
  • Create a HiAPI API key before calling GPT Image 2, and keep the key on your server.
  • This page documents request fields and code. Use the dedicated pricing guide linked in Model summary for current per-image rates, route differences, and batch budgets; do not hard-code prices in your app.
  • For prompt validation, start with 1K output. Increase resolution or switch to a higher-fidelity model only for final assets.

Best suited for

Accurate text rendering

Useful for menus, signs, UI screenshots, infographics, and any image where text must stay readable.

promptresolution
Poster and layout work

Use one detailed prompt to describe headlines, supporting copy, subject placement, and whitespace.

promptaspect_ratioresolution
Product and commerce images

Generate clean product visuals with consistent composition for product pages and social covers.

promptaspect_ratio
Long-prompt creative drafts

Control subject, style, material, camera, composition, and text content in one complex prompt.

prompt
Multi-format delivery

Adapt one creative direction into square, landscape, portrait, or ultrawide placements.

aspect_ratioresolution
Multiple routes

The beta route controls output via a size field; ext unlocks multi-ratio 4K. Each route is priced differently.

route

Request parameters

Route

Default route: full 1K/2K/4K resolutions and 16 aspect ratios (including auto), one flat rate per image.

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. Note: 5:4, 4:5, 3:1, 1:3, and 9:21 support 1K images only.

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

Image resolution. Note: 1:1 cannot be generated at 4K; auto or an unspecified aspect ratio can only be generated at 1K.

default 1K enum: 1K2K4K
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

Example requests

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 clean product photo of a red apple on a white table",
    "aspect_ratio": "1:1",
    "resolution": "1K"
  }
}
Square product creative

For product pages, social avatars, and square cover placements.

Request body
{
  "model": "gpt-image-2/text-to-image",
  "input": {
    "prompt": "A premium skincare bottle on a white acrylic surface, soft studio lighting, clean commercial product photography",
    "aspect_ratio": "1:1",
    "resolution": "1K"
  }
}
Portrait poster with text

Put the required words, hierarchy, and layout constraints directly into the prompt.

Request body
{
  "model": "gpt-image-2/text-to-image",
  "input": {
    "prompt": "A vertical launch poster with the exact headline \"SUMMER DROP\", small subtitle \"New arrivals\", bright product photography, clean grid layout, generous whitespace",
    "aspect_ratio": "9:16",
    "resolution": "1K"
  }
}
Production request with callback

Recommended production shape: create the task, then wait for callback.url to receive the terminal notification.

Request body
{
  "model": "gpt-image-2/text-to-image",
  "input": {
    "prompt": "A clean product photo of a red apple on a white table",
    "aspect_ratio": "1:1",
    "resolution": "1K"
  },
  "callback": {
    "url": "https://your-domain.com/hiapi/callback",
    "when": "final"
  }
}

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 generated image from output[].url.
  4. When status=fail, fix the request based on the returned error instead of retrying the same invalid payload.

FAQ

What is the GPT Image 2 API?

GPT Image 2 is HiAPI’s text-to-image generation API for product visuals, posters, and text-heavy layouts. You call it through the unified POST /v1/tasks endpoint with model gpt-image-2/text-to-image; it returns a taskId immediately, and you fetch the result by polling or callback.

How do I get an API key for GPT Image 2?

Create a key in the HiAPI dashboard under API keys and send it as a Bearer token in the request header. Keep the key on your server, not in client-side code. Create an API key

How much does the GPT Image 2 API cost?

The standard route uses a fixed per-image price for the selected resolution; other routes and specifications may differ. This page keeps the request contract, while the dedicated guide linked in Model summary covers current rates, batch budgets, and billing details.

Can GPT Image 2 render text inside images?

Yes. GPT Image 2 is strong at accurate text rendering for menus, posters, signage, infographics, and UI mockups — put the exact words and layout requirements directly in the prompt.

Which routes does gpt-image-2/text-to-image offer, and how do the parameters differ?

Three routes. Standard: aspect_ratio (including auto) plus resolution (1K/2K/4K). Beta: a different parameter shape — a size field replaces aspect_ratio and resolution. Ext: a multi-ratio 4K route (quality and resolution required) — see the ext tab under request parameters. Route prices may differ; use the pricing guide linked in Model summary for current costs.

How do I call the beta or ext route?

Pass the base model name with a top-level route parameter, e.g. route: 'beta', or spell the route into the model name, e.g. gpt-image-2/text-to-image@beta — the two are equivalent. Note that input parameters differ per route, so adjust the fields accordingly.

Next steps