Recipe 02 · recordInfo + callBackUrl
Polling without hammering
A video job takes minutes, not milliseconds, so a poller that checks every 200 ms is wasting requests and a poller that gives up after 60 seconds is throwing away finished videos. This recipe gives you a loop with sane defaults that are clearly your defaults, plus the webhook alternative.
What the docs actually say about polling
The Kinovi API reference says to poll recordInfo “every couple of seconds until status is success or fail”, and the Seedance 2.5 model page says “every few seconds”. It also says there is no separate per-hour rate limit — the documented limit is the per-account cap on tasks in flight. That is the whole of the official guidance on interval: there is no published SLA, no required backoff schedule and no retry header to read.
On how long to keep going, the Seedance 2.5 page says: “Poll for at least 20 minutes before treating a task as stuck.” The extend and edit pages say 15 minutes. Those are the provider's words, quoted here with the date we read them; they are a floor for patience, not a promise that a job finishes by then.
A loop you can ship
JavaScript
// Node 18+ — poll one Seedance job politely.
const BASE = "https://kinovi.ai/api/v1";
const headers = { Authorization: `Bearer ${process.env.KINOVI_API_KEY}` };
// Your numbers. None of these are official values.
const FIRST_WAIT_MS = 5_000;
const MAX_WAIT_MS = 30_000;
const GIVE_UP_AFTER_MS = Number(process.env.SEEDANCE_CLIENT_TIMEOUT_MS ?? 30 * 60_000);
export async function waitForTask(taskId) {
let wait = FIRST_WAIT_MS;
const started = Date.now();
for (;;) {
const res = await fetch(`${BASE}/jobs/recordInfo?taskId=${encodeURIComponent(taskId)}`, { headers });
if (res.status === 404 || res.status === 403) {
throw new Error(`recordInfo ${res.status}: wrong taskId or wrong key`);
}
if (res.ok) {
const task = await res.json();
if (task.status === "success") return task;
if (task.status === "fail") throw Object.assign(new Error(task.error?.message), { task });
// waiting | generating | anything new: keep going
}
// 5xx or network blip: fall through and try again later
if (Date.now() - started > GIVE_UP_AFTER_MS) {
throw Object.assign(new Error("client timeout"), { taskId }); // job may still finish
}
await new Promise((r) => setTimeout(r, wait + Math.random() * 1000));
wait = Math.min(wait * 1.5, MAX_WAIT_MS);
}
}Python
import os, random, time, requests
BASE = "https://kinovi.ai/api/v1"
HEADERS = {"Authorization": f"Bearer {os.environ['KINOVI_API_KEY']}"}
GIVE_UP_AFTER = float(os.environ.get("SEEDANCE_CLIENT_TIMEOUT_S", 30 * 60)) # your choice
def wait_for_task(task_id, first=5.0, cap=30.0):
wait, started = first, time.monotonic()
while True:
r = requests.get(f"{BASE}/jobs/recordInfo", params={"taskId": task_id}, headers=HEADERS, timeout=30)
if r.status_code in (403, 404):
raise RuntimeError(f"recordInfo {r.status_code}: wrong taskId or wrong key")
if r.ok:
task = r.json()
if task["status"] == "success":
return task
if task["status"] == "fail":
raise RuntimeError(task["error"]["message"])
if time.monotonic() - started > GIVE_UP_AFTER:
raise TimeoutError(f"stopped watching {task_id}; it may still finish")
time.sleep(wait + random.random())
wait = min(wait * 1.5, cap)Why it is shaped like this
- Growing gaps. The first checks are close together so a quick job is noticed quickly; later checks spread out because a job that has run for several minutes is not going to finish in the next second. The 5 s start and 30 s cap are illustrative — tune them.
- Jitter. If you submit a batch, a random half-second to second stops every poller hitting the API in lockstep.
- 403 and 404 stop the loop. They mean the ID is wrong or belongs to another key. Polling harder will not fix either.
- 5xx and network errors don't. One failed poll says nothing about the job. Try again on the next tick.
- Your timeout is a client decision. It is read from an environment variable on purpose, so nobody mistakes it for an official number. Set it above the provider's “stuck” floor quoted above.
Use callBackUrl instead of a tight loop
Add "callBackUrl": "https://your.app/hooks/kinovi" to the createTask body and Kinovi sends one POST when the task reaches success or fail. The body wraps the same object recordInfo returns, under data. Respond with any 2xx.
// A minimal callBackUrl receiver (any framework works the same way)
export async function POST(req) {
const body = await req.json(); // { code: 200, message: "success", data: { ...recordInfo } }
const task = body.data;
const status = task.status; // read status; data.state is a legacy alias
await saveTask(task.taskId, status, task.output?.[0]?.url ?? null, task.error ?? null);
return new Response("ok", { status: 200 }); // any 2xx
}The callback is sent once and is not retried. That sentence is in Kinovi's docs, and it shapes the design: if your endpoint is down for a deploy, the notification is gone. Keep a slow background poll (minutes apart) for any task that has not been settled by a webhook, and treat recordInfo as the source of truth.
Polling vs callback at a glance
| Situation | Prefer | Why |
|---|---|---|
| Script, notebook, CLI tool | Polling | No public endpoint needed; the process is alive anyway. |
| Web app with a job table | Callback + slow sweeper | No request load while jobs run; the sweeper covers missed deliveries. |
| Serverless function | Callback | A function that sleeps for minutes is paying to wait. |
| Batch of many jobs | Callback, or one poller over all IDs | Your concurrency cap limits how many are in flight anyway; one loop over the open set is simpler. |