Webhooks
A webhook tells your server when a task ends, so you don’t have to poll. You register one HTTPS endpoint, and Klap sends it a signed POST request for each event.
Polling keeps working exactly as before. Webhooks are optional.
Events
| Event | Sent when |
|---|---|
task.ready | A task finished successfully. Sent once per task |
task.failed | A task failed. Sent once per task |
task.pass_completed | A task that follows a live stream has new clips. Sent after each pass, before the task’s task.ready |
Every task ends with exactly one task.ready or task.failed. A live stream’s task sends task.pass_completed any number of times first, then task.ready once the stream has ended or was stopped and its last pass is done. If you ignore task.pass_completed, a live stream behaves like a long video.
Exports have no event yet: keep polling GET /projects/{folder_id}/{project_id}/exports/{export_id}.
Set Your Endpoint
Endpoint: PUT /webhook
PUT /v2/webhook
Authorization: Bearer <your-api-key>
Content-Type: application/json
{
"url": "https://example.com/klap/webhook"
}| Parameter | Type | Required | Description |
|---|---|---|---|
url | string | Yes | Where events are sent. Must be https and a public host |
rotate_secret | boolean | No | Set to true to replace the signing secret of an endpoint you already set |
{
"url": "https://example.com/klap/webhook",
"enabled": true,
"created_at": "2026-11-23T12:00:00Z",
"updated_at": "2026-11-23T12:00:00Z",
"secret": "whsec_..."
}secret is returned when the endpoint is first set and when you rotate it. It is not shown again, so store it. Changing the url keeps the same secret.
There is one endpoint per account. All your API keys share it, and tasks created on behalf of your managed users are reported to it too.
GET /v2/webhook returns the endpoint without its secret (404 when none is set). DELETE /v2/webhook removes it.
Payload
{
"id": "evt_8f3kQ2mZp0Lr7tWx1YbN",
"type": "task.pass_completed",
"created_at": "2026-11-23T12:31:07.000Z",
"data": {
"task": {
"id": "task_001",
"type": "video-to-shorts",
"status": "processing",
"output_type": "folder",
"output_id": "folder_001",
"live": { "state": "live", "pass_count": 2, "clipped_until_seconds": 5400 }
},
"pass": {
"number": 2,
"from_seconds": 3600,
"to_seconds": 5400,
"clip_ids": ["project_101", "project_102", "project_103"]
}
}
}data.taskis the Task Object asGET /tasks/{task_id}returns it at that moment.data.passis only ontask.pass_completed: the pass number, the part of the stream it covers (seconds since the start of the stream) and the IDs of the clips it made. Each ID is a project in the task’s folder.to_secondsis the end the pass asked for and can be a few tens of seconds past what the stream had recorded by then:live.clipped_until_secondsis where clipping actually stands.
Each request also carries these headers:
| Header | Value |
|---|---|
Klap-Event-Id | The event’s id |
Klap-Event-Type | The event’s type |
Klap-Signature | t=<unix seconds>,v1=<hex signature> |
Verify the Signature
The signature is an HMAC-SHA256 of <t>.<raw request body> with your secret. Compute it over the raw body, before any JSON parsing, and refuse requests whose t is more than 5 minutes old.
import crypto from "node:crypto";
function isFromKlap(secret, signatureHeader, rawBody) {
const parts = Object.fromEntries(signatureHeader.split(",").map((p) => p.split("=")));
const age = Math.abs(Date.now() / 1000 - Number(parts.t));
if (!parts.t || !parts.v1 || age > 300) return false;
const expected = crypto.createHmac("sha256", secret).update(`${parts.t}.${rawBody}`).digest("hex");
const a = Buffer.from(parts.v1, "hex");
const b = Buffer.from(expected, "hex");
return a.length === b.length && crypto.timingSafeEqual(a, b);
}Delivery and Retries
- Answer with any
2xxstatus within 5 seconds. Do the work after you answer. - Anything else, including a redirect, counts as a failure. Klap tries again after 1 minute, 5 minutes, 30 minutes, 2 hours and 6 hours, then gives up.
- An event can be delivered more than once. Use its
idto ignore one you have already handled. - Events can arrive out of order.
data.task.statusanddata.pass.numbersay where the task stood when the event was created. - If an event never reaches you, nothing is lost:
GET /tasks/{task_id}always has the current state.