ClipSDKDOCS
Webhooks (Python)

ClipSDK Webhooks in Python

Verify Clipsdk-Signature HMAC-SHA256 headers in Python 3 using raw request bytes, hmac.compare_digest constant-time checks, 300-second replay windows, and idempotent delivery handling.

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 Python

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.py (Python 3 stdlib HMAC verifier)python
import hashlib
import hmac
import json
import os
import time
from http.server import BaseHTTPRequestHandler, HTTPServer

WEBHOOK_SECRET = os.environ["CLIPSDK_WEBHOOK_SECRET"]
SEEN_KEYS: set[str] = set()


def verify_clipsdk_signature(
    raw_body: bytes, header_value: str, secret: str, tolerance_sec: int = 300
) -> bool:
    if not header_value:
        return False
    parts = {}
    for item in header_value.split(","):
        if "=" in item:
            k, v = item.strip().split("=", 1)
            parts[k] = v

    if "t" not in parts or "v1" not in parts:
        return False
    try:
        timestamp = int(parts["t"])
    except ValueError:
        return False

    if abs(int(time.time()) - timestamp) > tolerance_sec:
        return False

    signed_payload = f"{parts['t']}.".encode("utf-8") + raw_body
    expected_hex = hmac.new(
        secret.encode("utf-8"), signed_payload, hashlib.sha256
    ).hexdigest()
    return hmac.compare_digest(parts["v1"], expected_hex)


class WebhookHandler(BaseHTTPRequestHandler):
    def do_POST(self):
        if self.path != "/webhooks/clipsdk":
            self.send_response(404)
            self.end_headers()
            return

        length = int(self.headers.get("Content-Length", "0"))
        raw_body = self.rfile.read(length)
        sig = self.headers.get("Clipsdk-Signature", "")

        if not verify_clipsdk_signature(raw_body, sig, WEBHOOK_SECRET):
            self.send_response(401)
            self.end_headers()
            return

        idem_key = self.headers.get("Idempotency-Key", "")
        if idem_key and idem_key in SEEN_KEYS:
            self.send_response(200)
            self.end_headers()
            return
        if idem_key:
            SEEN_KEYS.add(idem_key)

        payload = json.loads(raw_body.decode("utf-8"))
        # Persist or enqueue background asset copy, then return 2xx within 15s
        print(payload["event"], payload["job"]["id"])
        self.send_response(200)
        self.end_headers()


if __name__ == "__main__":
    HTTPServer(("0.0.0.0", 8787), WebhookHandler).serve_forever()

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.