Skip to main content
The unified async task API provides a standardized submit → poll → retrieve workflow, abstracting away provider-specific differences.

Overview

AI tasks such as video generation, image generation, and music generation can take anywhere from tens of seconds to several minutes. To ensure a good user experience and system stability, these tasks are handled through an async task API:
  1. Submit a task — Send a generation request and immediately receive a task ID
  2. Poll for status — Use the task ID to check progress, or receive a callback notification
  3. Retrieve results — Once complete, get the generated resource URLs from the response

Submit a Task

POST /v1/task/submit

Request Parameters

Request Examples

Response Example


Query a Task

GET /v1/task/{task_id}

Request Examples

Response Examples

Task in progress:
Task completed (token-based billing):
Task completed (per-call billing):
Task completed (duration-based billing):
Task failed:

Task Statuses


Callback Notifications

When you include a callback_url in your submit request, the system will send a POST request to that URL whenever the task status changes. The callback body uses the same format as the query response:
If you send X-Billing-Detail: true when submitting the task, the callback request sent when the task finishes carries two request headers, X-Billing-Currency and X-Billing-Amount, with the task’s actual charge.
  1. The callback URL must be publicly accessible over HTTPS
  2. Callback requests have a 10-second timeout
  3. Callback URLs cannot point to localhost, 127.0.0.1, or the platform’s own domain
  4. Even with callbacks enabled, implement polling as a fallback to avoid missing notifications due to network issues

Complete Polling Example


Response Fields


Usage Information

After a task reaches a terminal state (completed / failed), some models include a usage field in the response that reports the actual resources consumed. The usage field is a tagged union: the type field distinguishes the metering unit.

type=tokens (token-based billing)

Used by Doubao / Vidu / Ali / Kling text-based / Gemini and other token-billed tasks:

type=duration (duration-based billing)

Used by Sora / Xai-video and other video generation tasks billed by output duration:

type=call (per-call billing)

Used by Midjourney, Suno, Kling video and other tasks billed per call. Returned only when the task succeeds (completed):
multiplier depends on the request parameters and the actual output: for example, Midjourney HD (--hd) is 2, a V7 draft is 0.5, and videos depend on resolution and count. When fewer outputs are delivered than requested, the multiplier follows what was delivered (a V8 draft that returns 4 images is 0.5). For models priced per credit, image or song (such as Kling and Vidu, priced per credit), multiplier is the quantity consumed by this task. multiplier only describes the spec, so the same request gets the same multiplier no matter who calls it. It does not include account-specific adjustments such as group or personal discounts, nor separately charged fees such as reference-image fees. To check how much each task actually cost, use the actual charge.
  • Tasks billed by the upstream’s actual cost (e.g., Flux) do not return a usage field
  • Per-call tasks that fail are fully refunded and do not return usage
  • The usage field is not returned while the task is queued or in_progress
  • Historical tasks and tasks where the upstream did not report usage data also omit this field
  • Sub-fields with a zero value (e.g., text_tokens: 0) are omitted

Actual Charge

Add the request header X-Billing-Detail: true when querying a task. Once the task has finished, the response carries two extra headers with the amount this task actually cost. Discounts, extra fees and failure refunds are already applied, so it matches your bill. The response body does not change.
cURL
The amount is given in the currency the model is priced in: CNY for models priced in CNY, USD for models priced in USD. Use the returned amount as is; do not convert it with an exchange rate yourself. If you also send X-Billing-Detail: true when submitting the task, later queries return these two headers even without it, and the callback request sent when the task finishes carries them as request headers too.

Supported endpoints

Every endpoint that queries a single task supports it: GET /v1/task/{task_id} on this page, plus the task query endpoints in each vendor’s official format, including Midjourney (/midjourney/task/{task_id} and /mj/task/{id}/fetch), the OpenAI video format GET /v1/videos/{id}, Kling, MiniMax, Suno, Luma, Runway, Replicate, Flux, Vidu, Doubao, Alibaba Model Studio, Ideogram, Mureka, xAI video, and Veo video in the native Gemini format. Official-format endpoints keep their official response body as is; the amount is only in the response headers. Endpoints that query several tasks at once do not return it, for example the Suno and Luma batch queries and the Midjourney query by condition. The new Kling query GET /kling/tasks?task_ids= returns it when exactly one task is queried. For all of the tasks above, if X-Billing-Detail: true was sent on submit, the callback request sent when the task finishes carries these two request headers; the callback body does not change.
  • Only returned after the task has finished (completed / failed); a failed task whose charge was refunded shows 0
  • Right after a task finishes, the headers may be briefly missing while settlement completes; query again shortly
  • Not returned without X-Billing-Detail: true (unless it was sent when submitting)
  • Browser clients can read these two response headers directly

Completion notifications for Flux models

  • To be notified when a task finishes, pass callback_url at the top level of the request body; every Flux model supports it.
  • webhook_url / webhook_secret inside input are not sent upstream. The official endpoints of flux-3-image, flux-3-video, flux-tools/video-edit-v1 and flux-tools/outpainting-v1 accept no webhook fields, so they are ignored there; use callback_url or polling.
  • Without a callback, poll GET /v1/task/{task_id} after submitting (every 3-10 seconds; video tasks usually take several minutes).

Notes

  1. Authentication uses standard Authorization: Bearer <API_KEY> headers
  2. The input parameters vary by model — click on the model in the Models page to view its documentation
  3. Recommended polling interval is 3–10 seconds to avoid excessive requests
  4. Resource URLs in task results may have expiration limits — download and save promptly
  5. To be notified when a Flux task finishes, use the top-level callback_url; see “Completion notifications for Flux models” above

Video Models

Provider-specific video generation API documentation

Image Models

Image generation API documentation