Skip to main content
Video, music, and some image models use asynchronous tasks. The create endpoint returns a task ID before the generated asset is ready.
1

Create a task

Call the generation endpoint and save the returned task ID. Depending on the provider, the field may be named id, task_id, or taskId.
2

Poll the task

Call the matching task endpoint until the task reaches a terminal state. Start with a two-to-five-second interval and use exponential backoff.
3

Read the result

Read the asset URL after the task succeeds. Download or copy the asset promptly because generated URLs may expire.
Status fields and values differ between providers. Follow the schema for the create and query endpoints instead of sharing unadapted status logic across models.

Production checklist

  • Set a maximum polling duration.
  • Retry 429, 502, 503, and 504 responses with exponential backoff and jitter.
  • Retry only the query request. Confirm idempotency before retrying a create request.
  • Store the task ID, model ID, and creation time so an interrupted worker can resume.
  • Download generated assets promptly instead of treating temporary URLs as permanent storage.

Troubleshoot task failures