How Async Tasks Work
1
Create a task
Send a
POST request to the appropriate generation endpoint (for example, /v1/sora/videos for Sora video generation). The API responds immediately with a task id and an initial status of queued. Keep this ID — you’ll need it to retrieve your result.2
Poll for status
Send a
GET request to /v1/result/{id} using the task ID you received. Repeat this request on a regular interval (every 30–60 seconds for video, every 2–5 seconds for images) until the status changes from queued or processing to a terminal state.3
Retrieve your result
When the status field returns
completed, the response includes a result URL (for example, video_url or image_url) containing your generated media. Download or store this URL promptly — result URLs expire after 24 hours.Task Statuses
Every task returned by the API carries astatus field. The following table describes each possible value:
Polling Best Practices
- Poll every 30–60 seconds for video generation to avoid unnecessary API calls while respecting server load.
- Poll every 2–5 seconds for image generation, which typically completes much faster than video.
- Stop polling immediately when the status is
completed,failed, orcancelled— further polling is wasteful and unnecessary. - Video URLs expire after 24 hours — download your generated video to your own storage as soon as generation completes.
- Image URLs also expire after 24 hours — save generated images to your own storage rather than relying on the temporary URL long-term.
- Do not retry on
failedstatus without reviewing theerrorfield first; the same prompt or parameters may continue to fail.
Code Example: Full Polling Loop
The example below creates a video generation task using the Sora model, then polls in a loop until the task completes or fails.Text chat APIs (OpenAI Chat, Claude Messages, and Gemini Native) are synchronous — they return the model’s response directly in the HTTP response body and do not use the async task pattern described on this page.