Generate AI Video with an API: Submit, Poll, Download (A Practical Guide to Async Tasks)

CQTAI

10/25/2026

#AI video#Veo#Sora 2#Async API#Developers

A chat completion comes back in a second or two. A video does not. Rendering a clip takes from tens of seconds to a few minutes, so no sensible video API holds the HTTP connection open until it is done. Instead you work with a task:

  1. Submit a request. The server accepts it and gives you a task id.
  2. Poll the task until it finishes.
  3. Fetch the result URL and save the file.

This guide shows that loop end to end with the model task endpoints, using Veo 3.1 and Sora 2 as examples.

The two endpoints

Each video model has a submit endpoint and a query endpoint:

POST https://api.novapi.ai/api/cqt/generator/{model}
GET  https://api.novapi.ai/api/cqt/info/{model}?id={taskId}

{model} here is the channel name, for example veo or sora2. The concrete model goes in the request body. Authentication is the same Bearer key as everywhere else, and every response is wrapped in { code, msg, data }.

Step 1: submit

A text-to-video request with Veo 3.1:

curl -X POST https://api.novapi.ai/api/cqt/generator/veo \
  -H "Authorization: Bearer $API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "veo-3.1",
    "prompt": "a drone shot flying over a misty mountain forest",
    "aspectRatio": "16:9",
    "duration": 8
  }'

On success data is simply the task id:

{ "code": 200, "msg": "success", "data": "<taskId>" }

A few request fields worth knowing, taken from the model pages:

  • Veo 3.1: duration is 4, 6 or 8 seconds. The default output is 720p, and hd: true asks for 1080p at an extra charge.
  • Sora 2: the model id is sora-2, aspectRatio is 16:9 or 9:16, and duration is 4, 8 or 12 seconds.
  • Image to video adds an input image URL. Check the capability page of the model you use for the exact field name.

Save the task id right away, in your database or at least in a log line. It is the only handle you have on that job.

Step 2: poll

curl "https://api.novapi.ai/api/cqt/info/veo?id=<taskId>" \
  -H "Authorization: Bearer $API_KEY"

While the job runs you get the task object with a status that is neither of the final ones. When it ends:

{
  "code": 200,
  "data": {
    "id": "<taskId>",
    "status": "succeeded",
    "resultUrl": "https://.../result.mp4",
    "createTime": "2026-06-15 10:00:00",
    "completeTime": "2026-06-15 10:02:00"
  }
}

The rules are short:

  • status = succeeded: data.resultUrl holds the video.
  • status = failed: data.errorMsg holds the reason.
  • Anything else means the job is still running. Keep polling.

Poll every 10 to 15 seconds. Polling every second does not make the video finish sooner, it only burns requests.

Step 3: a complete loop

Python, with requests:

import os
import time

import requests

BASE = "https://api.novapi.ai/api/cqt"
HEAD = {"Authorization": "Bearer " + os.environ["API_KEY"]}

submit = requests.post(
    BASE + "/generator/veo",
    headers=HEAD,
    json={
        "model": "veo-3.1",
        "prompt": "a drone shot flying over a misty mountain forest",
        "aspectRatio": "16:9",
        "duration": 8,
    },
).json()

if submit["code"] != 200:
    raise RuntimeError(submit["msg"])

task_id = submit["data"]
print("submitted", task_id)

deadline = time.time() + 15 * 60
while time.time() < deadline:
    time.sleep(12)
    info = requests.get(BASE + "/info/veo", headers=HEAD, params={"id": task_id}).json()
    data = info["data"]
    if data["status"] == "succeeded":
        print("video:", data["resultUrl"])
        break
    if data["status"] == "failed":
        print("failed:", data.get("errorMsg"))
        break
else:
    print("still running, check task", task_id, "later")

TypeScript, with fetch:

const base = "https://api.novapi.ai/api/cqt";
const headers = {
  Authorization: "Bearer " + process.env.API_KEY,
  "Content-Type": "application/json",
};

const submit = await (
  await fetch(base + "/generator/veo", {
    method: "POST",
    headers,
    body: JSON.stringify({
      model: "veo-3.1",
      prompt: "a drone shot flying over a misty mountain forest",
      aspectRatio: "16:9",
      duration: 8,
    }),
  })
).json();
if (submit.code !== 200) throw new Error(submit.msg);

const taskId: string = submit.data;
const sleep = (ms: number) => new Promise((r) => setTimeout(r, ms));

for (let i = 0; i < 75; i++) {
  await sleep(12_000);
  const info = await (
    await fetch(base + "/info/veo?id=" + taskId, { headers })
  ).json();
  const d = info.data;
  if (d.status === "succeeded") {
    console.log("video:", d.resultUrl);
    break;
  }
  if (d.status === "failed") {
    console.log("failed:", d.errorMsg);
    break;
  }
}

Note the loop has a deadline. A job you stop waiting for is not cancelled, so on timeout log the task id and check it later instead of submitting again.

Mistakes that cost money

Resubmitting because a poll looked slow. Each submit is a new task and a new charge. If a task seems stuck, keep polling the same id.

Polling without a stop condition. Always handle failed, and always set a deadline.

Losing the task id. If your process crashes between submit and poll, the id is the only way back to the result. Persist it first.

Treating resultUrl as permanent storage. It is a delivery link. Download the file to your own bucket as soon as the task succeeds, so your product does not depend on that link staying valid forever.

The unified endpoint

If you prefer the OpenAI Sora video format, there is also POST /v1/videos with GET /v1/videos/ID for polling and GET /v1/videos/ID/content for the download. It follows the same create-then-poll idea, with statuses queued, in_progress, completed and failed. The video guide describes it in full. Use one style consistently in a project, because the task ids and response shapes are different.

Billing, briefly

Video is billed per second or per task depending on the model, and the charge is taken when the task is submitted. The exact price of each model is on the pricing page, so this post does not repeat numbers that can change. For the rules on refunds and how to estimate cost, read our post on points and cost control.

Next steps

    Generate AI Video with an API: Submit, Poll, Download (A Practical Guide to Async Tasks)