LLM inference, image generation, and most data APIs are synchronous — they return the result in a single response. The async pattern only applies to endpoints that return a
task_id instead of a result.The pattern
Create a task
Send the generation request with the header
X-DashScope-Async: enable. The response returns immediately with a task_id and initial status (PENDING or RUNNING).Poll for completion
Call
GET /apis/v1/services/aigc/tasks?task_id={task_id} every few seconds until task_status is SUCCEEDED or FAILED.Example: video generation
1. Create the task
2. Poll the task
output (not nested under error):
3. Download the asset
Task lifecycle states
| Status | Meaning | Billing |
|---|---|---|
PENDING | Task accepted, queued for execution | Not billed yet |
RUNNING | Actively generating | Billed on success |
SUCCEEDED | Generation complete. output.video_url is populated | Billed in full |
FAILED | Generation failed. output.code and output.message explain why | Not billed |
CANCELED | Task was cancelled (e.g., user request or policy) | Partial billing possible |
UNKNOWN | The task_id is not recognized or has expired | — |
Polling best practices
Backoff on transient states
When status is
PENDING / RUNNING / UNKNOWN, wait before the next poll. A simple linear delay works; exponential is overkill for a bounded-duration job.Cap the total wait
Enforce a hard timeout (e.g., 5 minutes). If the task hasn’t completed, log the
task_id for later inspection and surface a timeout to the caller.Handle `FAILED` explicitly
A failed task is not billed, but you should inspect
error.code and error.message to decide whether to retry. Common causes: safety-policy violation, invalid prompt, upstream outage.Minimal poller (Python)
Concurrency limits
Async endpoints cap concurrent in-flight tasks per key. Typical default:| Endpoint | Concurrent tasks per key |
|---|---|
| Video synthesis | 3 |
| Image generation | 30 RPM (synchronous) |
429 on the create call. The Retry-After header tells you how long to wait. See Rate Limits for the full table.
Related
Video synthesis endpoint
Reference for the task-creation endpoint.
Task status endpoint
Reference for the polling endpoint.
Media Gen skill
Agent-skill wrapper that handles task polling for you.
Error Codes
Handling failures and retries.