AI Video API Webhooks: Stop Polling for Finished Clips
How an AI video API webhook works: two events, signed deliveries, retries, signature checks in Node and Python, and what to do when one is missed.
Updated 6 min read
An AI video API webhook is a POST request the API sends to your server when a clip finishes, so your code is told the result instead of asking for it every few seconds. On Frameport you add an endpoint once, and every generation of the workspace then ends with a signed delivery: generation.succeeded or generation.failed.
This guide covers why video jobs are asynchronous, when polling is still the right call, what a delivery contains, how to verify its signature in Node and Python, and what to do when your endpoint misses one. The examples use Seedance 2.5 and Veo 3.1; the events are the same for every model.
Why AI video generation is asynchronous
A video model does not answer within one HTTP request. POST /v1/videos/generations checks the request, holds its price on your balance and answers at once with 202 Accepted: a generation id, status: "queued" and reserved_usd, the price held. The clip renders after that.
The generation then moves from queued to running, and ends succeeded or failed. You learn which in one of two ways: you read the generation again until it settles (polling), or the API calls you when it does (a webhook).
Polling vs webhooks: when to use each
| Polling | Webhooks | |
|---|---|---|
| How it works | GET /v1/videos/generations/{id} every few seconds | One POST to your endpoint when the job settles |
| Fits | Scripts, notebooks, one-off batches, code with no public URL | Services, queues, many clips at once, clips started from the Studio |
| You run | A loop with a timeout | A public https endpoint |
| You handle | Backoff and timeouts | Signatures, retries and duplicates |
Reads are not counted against your rate limit, so a loop that reads every few seconds is fine for a script. A service that starts hundreds of clips should not keep that many loops open: let the webhook tell it.
Two other patterns show up in the same searches. Long polling holds a request open until something changes, and WebSockets keep a two-way connection. The API offers neither: a read is a plain GET that answers at once, and completion is pushed by webhook. If a browser UI needs live status (a React app, say), let your server receive the webhook and pass the news to the page over the channel your app already uses. Never call the API from the browser: the key spends money and belongs on your server.
Many teams use both: webhooks for the normal path, and a read by id when a delivery is late or missing.
The two events: succeeded and failed
Add an endpoint under Webhooks in the dashboard: an https URL on the public internet, and the events it takes, generation.succeeded, generation.failed or both. Each endpoint covers every generation of the workspace, whether it started from an API key, the Studio or the MCP server, and a workspace holds up to 10 endpoints. The signing secret, whsec_…, is shown once, when you add the endpoint.
A delivery is a POST with a JSON body: its own id (whd_…), the event, when it happened, and in data the generation exactly as GET returns it. Three headers come with it: Frameport-Signature, Frameport-Event and Frameport-Delivery, the same id as in the body.
{
"id": "whd_5f1c0a9e3b7d42c8a61e0f93",
"type": "generation.succeeded",
"created_at": "2026-11-28T10:01:12.000Z",
"data": {
"id": "gen_9sLq2VbX7mN4kR1tYc8WpE",
"object": "generation",
"type": "video",
"model": "seedance-2-5",
"status": "succeeded",
"reserved_usd": 1.35,
"cost_usd": 1.35,
"outputs": [{
"id": "file_2Tn7XcQ9vLm4Ra8Ws1KbZd",
"status": "succeeded",
"url": "https://frameport.ai/v1/files/file_2Tn7XcQ9vLm4Ra8Ws1KbZd?expires=1795864200&signature=...",
"url_expires_at": "2026-11-28T11:10:00.000Z",
"content_type": "video/mp4",
"cost_usd": 1.35
}],
"error": null,
"created_at": "2026-11-28T10:00:00.000Z",
"completed_at": "2026-11-28T10:01:12.000Z"
}
}A failed generation arrives as generation.failed, with cost_usd at 0 and the reason in error.code: generation_failed, timeout, or content_policy when the model refused the job after it started. The hold has already gone back to your balance. An image batch counts as succeeded when at least one of its images did: check each output's status, since only the outputs that succeeded are charged.
The file links in a delivery are signed when it is sent and open without a key for about an hour. If you download later, read the generation again for a fresh link.
Verify the signature in Node and Python
Anyone who learns your endpoint's URL can post to it, so check every delivery before you act on it. The Frameport-Signature header reads t=<unix seconds>,v1=<hex>. v1 is the HMAC-SHA256 of the timestamp, a dot and the raw request body, keyed with the endpoint's secret. Compute the same HMAC over the bytes you received, compare in constant time, and refuse a timestamp more than five minutes old, so an old delivery cannot be replayed.
import crypto from 'node:crypto'
import http from 'node:http'
const SECRET = process.env.WEBHOOK_SECRET // whsec_..., shown once when you add the endpoint
const handled = new Set() // delivery ids already processed: keep them in your database
function verify(rawBody, header, toleranceSeconds = 300) {
if (!header) return false
const parts = Object.fromEntries(header.split(',').map(part => part.trim().split('=')))
const age = Math.abs(Date.now() / 1000 - Number(parts.t))
if (!parts.t || !parts.v1 || !(age <= toleranceSeconds)) return false
const expected = crypto.createHmac('sha256', SECRET).update(`${parts.t}.${rawBody}`).digest('hex')
return expected.length === parts.v1.length
&& crypto.timingSafeEqual(Buffer.from(expected), Buffer.from(parts.v1))
}
http.createServer((req, res) => {
const chunks = []
req.on('data', chunk => chunks.push(chunk))
req.on('end', () => {
const raw = Buffer.concat(chunks).toString('utf8')
// Node lowercases header names
if (req.method !== 'POST' || !verify(raw, req.headers['frameport-signature'])) {
res.writeHead(400).end()
return
}
const event = JSON.parse(raw)
res.writeHead(204).end() // answer first: 10 seconds at most
if (handled.has(event.id)) return // a retry of a delivery already handled
handled.add(event.id)
const gen = event.data
if (event.type === 'generation.succeeded') {
console.log('ready', gen.id, gen.model, 'charged', gen.cost_usd) // queue the download here
}
else {
console.log('failed', gen.id, gen.error.message) // nothing was charged
}
})
}).listen(3000, () => console.log('listening on :3000'))import hashlib
import hmac
import json
import os
import time
from flask import Flask, request
app = Flask(__name__)
SECRET = os.environ["WEBHOOK_SECRET"] # whsec_..., shown once when you add the endpoint
handled = set() # delivery ids already processed: keep them in your database
def verify(raw: bytes, header: str, tolerance: int = 300) -> bool:
parts = dict(part.strip().split("=", 1) for part in header.split(",") if "=" in part)
if not parts.get("t", "").isdigit() or "v1" not in parts:
return False
if abs(time.time() - int(parts["t"])) > tolerance:
return False
expected = hmac.new(SECRET.encode(), parts["t"].encode() + b"." + raw, hashlib.sha256).hexdigest()
return hmac.compare_digest(expected, parts["v1"])
@app.post("/hooks/generations")
def generation_settled():
raw = request.get_data()
if not verify(raw, request.headers.get("Frameport-Signature", "")):
return "", 400
event = json.loads(raw)
if event["id"] not in handled: # every retry carries the same id
handled.add(event["id"])
gen = event["data"]
print(event["type"], gen["id"], gen["status"], gen["cost_usd"])
return "", 204Two details matter. Sign the raw bytes, never a JSON object you parsed and serialized again: a parser that reorders keys or changes spacing breaks the match. And answer within 10 seconds: a delivery that gets no 2xx in time counts as failed, even if your code finished later. Queue the download, answer, then do the work.
Retries and duplicate deliveries
A delivery that does not get a 2xx (an error status, no answer within 10 seconds, or a redirect) is sent again after 1, 5 and 15 minutes: four attempts in all. Every attempt carries the same delivery id, so keep the ids you have handled and skip a repeat, as both receivers above do.
Plan for two more kinds of repeat. A poll and a webhook can both see the same result, and two endpoints subscribed to the same event each get their own delivery, with its own id. Key the real work (the download, the database row, the email to your user) on the generation id, and make it safe to run twice.
When your endpoint goes down
An endpoint whose deliveries all fail for 24 hours, at least 10 in a row, is turned off, and everyone in the workspace who manages webhooks gets an email. Turn it back on under Webhooks once it answers again. The events from the gap are not sent again, so catch up with GET /v1/generations: it lists the workspace's generations newest first, filtered by status and date, a page at a time.
import os
import requests
API = "https://frameport.ai/v1"
HEADERS = {"Authorization": f"Bearer {os.environ['FRAMEPORT_API_KEY']}"}
def handle(gen: dict) -> None:
# The function your webhook calls, safe to run twice
print(gen["id"], gen["model"], gen["status"], gen["cost_usd"])
params = {"status": "succeeded", "created_after": "2026-11-27T00:00:00Z", "limit": 100}
while True:
page = requests.get(f"{API}/generations", headers=HEADERS, params=params).json()
for gen in page["data"]:
handle(gen)
if not page["has_more"]:
break
params["cursor"] = page["next_cursor"]Run it again with status=failed to close the jobs that failed meanwhile. A list does not move a running generation forward: read one by id, and it is brought up to date. The generations reference has every filter, and the webhooks reference covers deliveries and signatures.
For the polling side of the same job, the guides to the video generation API in Python and the AI video API in Node.js build the submit, poll and download steps around these events. When each approach fits is weighed in polling vs webhooks, and what the code of a failed job means, and whether to retry it, is in AI video API error codes.
FAQ
What is an API webhook?
An HTTP request that a service sends to a URL you choose when something happens on its side. For an AI video API, it is the API telling your server that a clip has finished or failed, with the result in the body, so your code does not have to keep asking.
Should I use polling or webhooks for AI video?
Poll in scripts and notebooks, where a short loop is simplest and you have no public URL. Use webhooks in a service that runs many clips or reacts to clips started elsewhere, such as the Studio. Reads are not counted against your rate limit, so polling every few seconds is fine.
Do I get a webhook when a video fails?
Yes, when the endpoint subscribes to generation.failed. The delivery carries the generation with status: "failed", the reason in error, and cost_usd at 0: the hold went back to your balance.
Can I receive webhooks on localhost?
Not directly. An endpoint must be an https URL on a public host; private and local addresses are refused, and they are checked again at each delivery. While you develop, run a tunnel that gives your machine a public https address, or poll by id until you deploy.
Do Veo 3.1 clips send the same webhooks as Seedance?
Yes. Every model in the catalog ends with the same two events and the same body, so one receiver handles Veo 3.1, Seedance 2.5 and the rest.