ClipSDKDOCS
Webhooks (Node.js)

ClipSDK Webhooks in Node.js

Verify Clipsdk-Signature HMAC-SHA256 headers in Node.js using raw body bytes, constant-time timingSafeEqual comparison, 300-second replay checks, and Idempotency-Key deduplication.

Signature
HMAC-SHA256
Clipsdk-Signature: t=<unix>,v1=<hex>
Replay Window
300 seconds
Reject stale timestamps past 5 minutes
Retry Policy
5 Attempts
0s, +10s, +1m, +5m, +30m (15s timeout)

Webhook Headers & Delivery Contract

ClipSDK POSTs job.succeeded and job.failed JSON events to your HTTPS webhook_url with Clipsdk-Signature, Clipsdk-Job-Id, Clipsdk-Attempt, and Idempotency-Key headers.

HeaderFormat / ExamplePurpose
Clipsdk-Signaturet=1796566019,v1=8a3f...Unix timestamp plus hex HMAC-SHA256 of "<t>.<rawBody>" keyed with your webhook secret
Clipsdk-Job-Idjob_3k9x0c2m1q8w7e6r5t4yIdentifier of the finished clipping job
Clipsdk-Attempt1 to 51-based delivery attempt counter
Idempotency-Key<job_id>:<status>Stable deduplication key identical across retries for the same job outcome
User-Agentclipsdk-webhooks/1Fixed ClipSDK webhook sender identifier

Your webhook_url must use https:// on the default port (443) with no embedded user:pass@ credentials. Any 2xx HTTP response marks the event delivered. HTTP 3xx redirects are treated as failures and trigger a retry.

Webhook Event Payload Schema

Every webhook request body matches { event, job }, delivering the complete finished Job object so your consumer can ingest clips without an extra GET call.

POST webhook_url JSON bodyjson
{
  "event": "job.succeeded",
  "job": {
    "id": "job_3k9x0c2m1q8w7e6r5t4y",
    "op": "clips",
    "status": "succeeded",
    "stage": null,
    "created_at": "2026-12-06T14:01:02Z",
    "finished_at": "2026-12-06T14:04:19Z",
    "usage": { "source_minutes": 38.4, "clips": 5, "output_seconds": 196.2 },
    "pricing": { "basis": "source_minutes", "reason": null, "quality_multiplier": 1 },
    "result": {
      "source": { "duration_s": 2304, "language": "en", "speakers": null },
      "clips": [
        {
          "rank": 1,
          "score": 91,
          "title": "Why 90-second intros kill viewer retention",
          "video": "https://api.clipsdk.com/f/clip_rank1.mp4",
          "poster": "https://api.clipsdk.com/f/clip_rank1.jpg",
          "srt": "https://api.clipsdk.com/f/clip_rank1.srt",
          "vtt": "https://api.clipsdk.com/f/clip_rank1.vtt"
        }
      ],
      "locked": null
    },
    "error": null,
    "poll_url": "https://api.clipsdk.com/v1/jobs/job_3k9x0c2m1q8w7e6r5t4y"
  }
}

When a job fails, event is "job.failed", job.status is "failed", job.result is null, job.error contains { code, message }, and billing is $0. See all 12 job error codes in Pricing & Limits.

Verify Clipsdk-Signature in Node.js

Compute HMAC-SHA256 over the exact string "<t>.<rawBody>" using your webhook secret, verify with constant-time equality, and reject timestamps older than 300 seconds.

Always Hash the Raw Request Bytes

Never parse and re-stringify JSON before verifying Clipsdk-Signature. Whitespace or key-order changes invalidate the HMAC digest.

webhook-server.mjs (Node 20+ HMAC verifier)javascript
import crypto from "node:crypto";
import http from "node:http";

const WEBHOOK_SECRET = process.env.CLIPSDK_WEBHOOK_SECRET;
if (!WEBHOOK_SECRET) throw new Error("Set CLIPSDK_WEBHOOK_SECRET");

export function verifyClipsdkSignature(rawBody, headerValue, secret, toleranceSec = 300) {
  if (!headerValue) return false;
  const parts = {};
  for (const item of headerValue.split(",")) {
    const [k, v] = item.trim().split("=");
    if (k && v) parts[k] = v;
  }

  const timestamp = Number(parts.t);
  if (!Number.isFinite(timestamp) || !parts.v1) return false;
  if (Math.abs(Math.floor(Date.now() / 1000) - timestamp) > toleranceSec) return false;

  const expectedHex = crypto
    .createHmac("sha256", secret)
    .update(`${parts.t}.${rawBody}`)
    .digest("hex");

  const actual = Buffer.from(parts.v1, "hex");
  const expected = Buffer.from(expectedHex, "hex");
  return actual.length === expected.length && crypto.timingSafeEqual(actual, expected);
}

const seenKeys = new Set();

http.createServer((req, res) => {
  if (req.method !== "POST" || req.url !== "/webhooks/clipsdk") {
    res.writeHead(404).end();
    return;
  }

  const chunks = [];
  req.on("data", (chunk) => chunks.push(chunk));
  req.on("end", () => {
    const rawBody = Buffer.concat(chunks).toString("utf8");
    const sig = req.headers["clipsdk-signature"];
    if (!verifyClipsdkSignature(rawBody, String(sig ?? ""), WEBHOOK_SECRET)) {
      res.writeHead(401).end("Invalid signature");
      return;
    }

    const idemKey = String(req.headers["idempotency-key"] ?? "");
    if (idemKey && seenKeys.has(idemKey)) {
      res.writeHead(200).end("Already processed");
      return;
    }
    if (idemKey) seenKeys.add(idemKey);

    const payload = JSON.parse(rawBody);
    // Acknowledge quickly within 15s, then mirror /f/{key} files asynchronously
    queueMicrotask(() => {
      console.log(payload.event, payload.job.id, payload.job.result?.clips?.length ?? 0);
    });
    res.writeHead(200).end("ok");
  });
}).listen(8787);

Retry Schedule & Timeout Rules

ClipSDK retries failed or timed-out webhook deliveries up to 5 total attempts (0s, +10s, +1m, +5m, +30m) using a 15-second timeout and identical request body bytes.

AttemptDelay After Previous FailureTimeoutSuccess Criterion
Attempt 1Immediate (0s)15 secondsAny 2xx status code (no redirects)
Attempt 2+10 seconds15 secondsSame payload body and Idempotency-Key
Attempt 3+1 minute15 secondsSame payload body and Idempotency-Key
Attempt 4+5 minutes15 secondsSame payload body and Idempotency-Key
Attempt 5+30 minutes15 secondsFinal attempt; poll GET /v1/jobs/{id} to reconcile

Production Consumer Checklist

Return HTTP 200 inside 15 seconds, deduplicate on Idempotency-Key in durable storage, and mirror 7-day /f/{key} files into your own bucket asynchronously.

  • Decouple Heavy Downloads: Never download multi-megabyte MP4 files synchronously inside the webhook HTTP handler. Store the verified event in your database or queue, reply 200, and copy clip.video, clip.poster, clip.srt, and clip.vtt from a background worker.
  • Persist Idempotency-Key: Store <job_id>:<status> with a unique constraint in Postgres or Redis so network timeouts after commit never duplicate user notifications or social posts.
  • Reconcile Missed Deliveries: Run a lightweight periodic sweeper calling GET /v1/jobs/{id} on any job still marked running after 30 minutes to recover cleanly from extended endpoint outages.
  • Zero-Dependency Reference Scripts: Download the runnable verifier and --self-test harness from bitgate/clipsdk-api-skills.