Notice: MAI Image 2.7 launch limited-time 20% off, covering the full text-to-image and image editing lineup, try it now
Notice: Black Friday 2026 × Cyber Monday: Get up to 30% extra on top-ups, DeepSeek free to use · View the promotion
Open navigation

Media generation API

/v1/tasks is HiAPI’s unified async API: every async generation model — image, video, and audio — shares this one entry point, with one request format, one state machine and one callback contract. Switching models only means changing model and input.

  1. Submit a task

    POST /v1/tasks with model and input. You get a taskId right away while generation continues in the background.

  2. Get the result

    Poll GET /v1/tasks/:id until the task is terminal, or set callback.url at creation time and HiAPI pushes the result to you.

For runnable Node.js image generation, task polling, and signed video Webhook code, see the public HiAPI API examples repository.

The fields of input are defined per model — see the relevant model page. Shared parameters such as model / route / callback are fully documented on Create a task.

Endpoints

All requests use the same Base URL:

https://api.hiapi.ai
MethodPathPurpose
POST/v1/tasksCreate a task, returns taskId
GET/v1/tasksList tasks (paginated, newest first)
GET/v1/tasks/:idGet task detail: status, output, or failure reason

Request headers

The three endpoints share the following headers; Content-Type and Idempotency-Key apply only to POST /v1/tasks.

HeaderValueRequiredNotes
AuthorizationBearer YOUR_API_KEYyesAccount API key. Required on every request.
Content-Typeapplication/jsonnoOptional. The body is always parsed as JSON; if sent, only application/json is accepted.
Idempotency-Keyorder-42-submitnoOptional. Idempotency key — retries with the same key create the task only once.

Authentication

Carry your account API key in the Authorization header as Bearer YOUR_API_KEY. Keys are created and managed in the console — see Authentication.

Task ownership

A task belongs to the account that created it. Querying the same taskId from any other account returns 404.

Content type

Content-Type is optional — the request body is always parsed as JSON. The rules in one table:

Content-Type you sendBehavior
Header omitted✅ Processed normally
application/json (parameters like charset are fine)✅ Processed normally
Anything else (text/plain, form types, …)❌ 415 UNSUPPORTED_MEDIA_TYPE

Idempotency key

Add an Idempotency-Key header to POST /v1/tasks (any UTF-8 string, up to 255 bytes) and network timeouts or client auto-retries can no longer create duplicate tasks or duplicate charges. Idempotency is scoped to the account that owns the API key — rotating keys mid-way doesn’t affect it.

ScenarioPlatform behavior
First submitCreates the task, returns taskId
Same key + same body replayedNo new task — returns the original taskId with the header Idempotent-Replay: true
Same key + different body422 IDEMPOTENCY_KEY_MISMATCH — fix your key construction, do not retry
Same key while the first request is still in flight409 IDEMPOTENCY_KEY_PROCESSING — retry after Retry-After (5 seconds)
Same key after the original task failedStill replays the failed task (within ~24h) — to run it again, use a new key
More than 24 hours after the first submitKey expired — treated as a new request

Choosing a key

Use a unique business-side identifier, e.g. an order number like order-42-submit. Requests without the header behave exactly as before.

This covers idempotency in the submit direction (you retry; the platform creates the task only once). Idempotency of callback delivery (HiAPI may deliver twice; you deduplicate by taskId) is described in the Callbacks section below — the two are independent.

Status information

Read the result of a call in three layers: the HTTP status (was this request accepted), the business error code (why it was rejected or failed), and the task status (how far the async generation has progressed).

HTTP status codes

StatusMeaning
200Success (task detail returns 200 even when status=fail; the failure is in the body’s error)
400Invalid request — see error_code below
402Insufficient balance — the task is not created and nothing is charged; top up and retry
404Task does not exist or does not belong to the current account
409Idempotency key conflict: the first request with this key is still in flight; retry after Retry-After
415Content-Type is not application/json; switch to application/json or drop the header, then retry
422Idempotency key mismatch: same key with a different request body; fix your key construction, do not retry
503Platform temporarily unavailable; retry later with exponential backoff

Business error codes

The synchronous failure response of POST /v1/tasks (error_code) and a terminal task’s error.code share this enum; codes marked “creation-only” appear only in synchronous responses, never in a terminal task’s error.code.

CodeMeaningWhat to do
INVALID_REQUESTInvalid request body (missing field / wrong type / invalid callback.url / model rejects the input), or the idempotency key exceeds 255 bytes / is not valid UTF-8Fix the request; do not retry the same request
PROMPT_TOO_LONGPrompt is too long; not chargedShorten the prompt and retry
RATE_LIMITEDRequest rate limit exceeded (typically HTTP 429)Retry later; avoid immediately resubmitting the same request
CONTENT_POLICY_VIOLATIONContent did not pass safety reviewRevise the prompt or input and retry
TEMPORARILY_UNAVAILABLEGeneration service is temporarily unavailableRetry later; contact support if the problem persists
UNSUPPORTED_MEDIA_TYPEContent-Type carries a value other than application/json (HTTP 415, creation-only)Switch to application/json or drop the header, then retry
INSUFFICIENT_QUOTAInsufficient account balance (HTTP 402, creation-only); the task is not created and nothing is chargedTop up and retry; you can set balance alerts in the dashboard
IDEMPOTENCY_KEY_PROCESSINGThe first request with this Idempotency-Key is still in flight (HTTP 409, creation-only)Retry after Retry-After (5 seconds); see Idempotency key
IDEMPOTENCY_KEY_MISMATCHSame Idempotency-Key with a different request body (HTTP 422, creation-only)Fix your key construction; do not retry
MODEL_UNAVAILABLEModel unavailable (disabled, no permission, temporarily unavailable)Retry shortly, or switch models
TASK_NOT_FOUNDTask does not exist, or is not visible to this account (HTTP 404; only the GET /v1/tasks/:id read path returns it, as an extra error_code field)Check the task ID and the account that owns the API key; do not retry
MODEL_PRICING_UNAVAILABLEThe model has no price configured and cannot be used right now (HTTP 503; a deterministic configuration error, not a transient failure)Do not retry — retrying will not help; contact support
TASK_FAILEDTask failedRetry once; contact support if the problem persists
TASK_TIMEOUTTask timed outRetry the task
STORAGE_UNAVAILABLEOutput storage errorRetry; contact support if the problem persists

Failed tasks are never charged

The amount reserved at creation is automatically refunded in full once a task reaches the failed terminal state.

Failure responses look like:

{
  "code": 400,
  "message": "invalid request",
  "data": null,
  "error_code": "INVALID_REQUEST"
}

Task status enum

statusMeaningReturns output?
queuedEnqueued, not startedNo
handlingProcessingNo
archivingDone, output being preparedNo
successTerminal: complete, output availableYes
failTerminal: failedNo, returns error
   POST /v1/tasks ──► queued ──► handling ──► archiving ──► success  (terminal)
       (200 / taskId)              │             │
                                   ▼             ▼
                                  fail          fail   (terminal)

   success / fail triggers the callback (if callback.url was set)

The only terminal states are success / fail; they never convert to each other, and a taskId’s result is fixed once terminal.

Callbacks

Async tasks support two ways to get results:

  1. Polling — after creating a task, request GET /v1/tasks/:id at intervals until status is terminal.
  2. Callback (Webhook) — provide callback.url when creating the task, and HiAPI POSTs to that URL when the task reaches a terminal state (success or fail).

The callback request:

  • Method POST, Content-Type application/json
  • Body is identical to the data field of GET /v1/tasks/:id (the task detail object)
  • callback.when currently supports only final (both success and fail fire a callback)
  • callback.url must be a valid http(s) URL, so both public HTTPS endpoints and plain-HTTP endpoints reachable from the platform are accepted

Set a “Webhook signing key” on the account settings page in the HiAPI console (shared secret, 16–256 chars; empty means no signing).

  • Not set: callback requests carry no signature header.
  • Set: each callback carries
    • X-HiAPI-Timestamp: Unix seconds (string)
    • X-HiAPI-Signature: hex( HMAC_SHA256(secret, timestamp + "." + body) )

Receiver verification (Python pseudocode):


ts   = request.headers["X-HiAPI-Timestamp"]
sig  = request.headers["X-HiAPI-Signature"]
body = request.raw_body  # raw bytes, not JSON-parsed

expected = hmac.new(
    secret.encode(),
    ts.encode() + b"." + body,
    hashlib.sha256,
).hexdigest()

assert hmac.compare_digest(expected, sig), "bad signature"
# Recommended: reject requests where abs(now - int(ts)) > 5 minutes (replay protection)

Delivery retries and idempotency

ItemBehavior
EnqueueOnce, when the task reaches success or fail
SuccessReceiver returns HTTP 2xx
RetryNon-2xx / timeout / network error is retried at immediately → +1 min → +5 min → +20 min. That is the first delivery plus 3 retries — 4 deliveries in total, including the first
TerminalAfter those 4 deliveries fail, no more retries; does not affect the task’s own state

Terminal callbacks are delivered “at least once”, not “exactly once”. Deduplicate by taskId on your side.

This covers callback delivery idempotency (HiAPI may deliver twice; you deduplicate by taskId). Idempotency in the submit direction (you retry a request; the platform creates the task only once) is handled by the Idempotency-Key header — the two are independent.