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:- Submit a task — Send a generation request and immediately receive a task ID
- Poll for status — Use the task ID to check progress, or receive a callback notification
- Retrieve results — Once complete, get the generated resource URLs from the response
Submit a Task
POST /v1/task/submitRequest Parameters
Request Examples
Response Example
Query a Task
GET /v1/task/{task_id}Request Examples
Response Examples
Task in progress:Task Statuses
Callback Notifications
When you include acallback_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:
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.
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
usagefield - Per-call tasks that fail are fully refunded and do not return
usage - The
usagefield is not returned while the task isqueuedorin_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 headerX-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 shows0 - 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_urlat the top level of the request body; every Flux model supports it. webhook_url/webhook_secretinsideinputare not sent upstream. The official endpoints offlux-3-image,flux-3-video,flux-tools/video-edit-v1andflux-tools/outpainting-v1accept no webhook fields, so they are ignored there; usecallback_urlor polling.- Without a callback, poll
GET /v1/task/{task_id}after submitting (every 3-10 seconds; video tasks usually take several minutes).
Notes
Related Links
Video Models
Provider-specific video generation API documentation
Image Models
Image generation API documentation