Skip to main content
Video and image generation are compute-intensive operations that can take anywhere from a few seconds to several minutes to complete. Rather than making you wait for a synchronous HTTP response that could time out, GlobalAI OPC uses an asynchronous task model: you submit a generation request, receive a task ID immediately, and then poll a separate endpoint to check progress until your result is ready.

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 a status 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, or cancelled — 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 failed status without reviewing the error field 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.
Result URLs (both video and image) expire 24 hours after generation completes. Download and store your generated media in your own storage immediately after retrieval — you cannot regenerate an expired URL without re-running the full generation task.
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.