Skip to content

For AI agents: every API docs page in one plain-text file is at /docs/llms-full.txt, and the documentation index is at /llms.txt. This page is available as Markdown at https://diffio.ai/docs/developers/webhooks.md, and every docs URL returns Markdown when requested with Accept: text/markdown.

Webhooks: events, signatures and retries

Webhooks notify your server with signed HTTP POST events whenever a project, generation, separated-track stem, export or transcript assistant turn finishes or fails, so your application does not need to poll.

How webhooks work

  1. Diffio: State transition. A generation, project, stem, export or turn completes or fails
  2. Signed POST: JSON event. svix-id, svix-timestamp, svix-signature headers
  3. Your endpoint: Verify, then answer 200OK.. Answer fast; any non-2xx response is retried with backoff
  4. Background job: Fetch media or details. Call generation media or get generation, then update records
Account scope and portal model

Webhooks belong to your whole Diffio account rather than a single API key. Once enabled, events fire across all API keys and all end users on the account; every event payload carries data.end_user (null when created without Diffio-End-User).

Development and production use separate webhook portals and applications. Disable CSRF middleware on your webhook route so incoming signed POST requests reach your signature check untouched.

Add an endpoint

  1. 1

    Open the webhook portal

    Call POST /webhooks/portal with an API key that has Write permission (a read-only key gets 403Forbidden: the key lacks permission.). The first call creates your account's webhook application and turns event delivery on. Open the returned url right away: portal links are short-lived, so request a fresh link each time you visit.

    Do not send the Diffio-End-User header on POST /webhooks/portal; the endpoint is account-wide and refuses that header with 403Forbidden: the key lacks permission. (permission_denied). Both SDKs leave it off this call, even on a client created for an end user.

    from diffio import DiffioClient
    
    client = DiffioClient()  # reads DIFFIO_API_KEY
    portal = client.webhooks.portal()
    print(portal.url, portal.event_types)
    Webhook portal endpoints list with the Add Endpoint button.
    Select Add Endpoint in the webhook portal. Full-size screenshot
    No server yet

    If you do not have an HTTPS receiver deployed yet, use the portal to create a temporary test receiver URL so you can inspect real deliveries while building your handler.

  2. 2

    Add your endpoint URL and events

    Paste your HTTPS endpoint URL and tick the events you handle. Leaving every box clear subscribes the endpoint to all of them.

    • Generationsgeneration.completedgeneration.failedgeneration.stems_readygeneration.stems_failed
    • Projectsproject.readyproject.failed
    • Exportsexport.readyexport.failed
    • Assistant turnstranscript_assistant_turn.completedtranscript_assistant_turn.failed
    About the portal's event list
    • It also lists generation.queued and generation.processing, kept for an older API. This API never sends them; follow progress with Get a generation.
    • Its sample payloads for generation.completed and generation.failed show that older schema. Real deliveries use the { type, id, created_at, data } envelope under Events and payloads.
  3. 3

    Save the signing secret

    Open the new endpoint's details page, reveal its whsec_... signing secret and store it as DIFFIO_WEBHOOK_SECRET in your secret manager. Each endpoint has its own unique secret.

    The Signing Secret row of the endpoint details, with the hidden secret and its reveal button.
    Copy the Signing Secret from the endpoint details. Full-size screenshot

Test endpoints

  1. Trigger: Run a short restore. Upload a short clip and restore it; there is no test-event API endpoint
  2. Inspect: Portal message log. View each delivery's payload and your endpoint's response in the portal
  3. Confirm: Signature + 200OK.. Your receiver verifies svix-signature and returns a 2xx status

Events and payloads

Every delivery is { type, id, created_at, data }. id is "evt_" plus 32 hex characters, the same on every retry, so dedupe on it. Only finished or failed states send events, never progress.

Every data has id, project_id, end_user and status. The table lists what each event adds.

Event typedata.objectstatusAlso in data
generation.completedobject generationstatus "complete"also kind ("restore" or "edit")
generation.failedobject generationstatus "failed"also kind, error_code
generation.stems_readyobject generationstatus the generation'salso kind, stems_status: "ready"
generation.stems_failedobject generationstatus the generation'salso kind, stems_status: "failed"
export.readyobject generation_exportstatus "ready"also generation_id; id ends -inline for inline exports
export.failedobject generation_exportstatus "failed"also generation_id
transcript_assistant_turn.completedobject transcript_assistant_turnstatus "complete"also generation_id
transcript_assistant_turn.failedobject transcript_assistant_turnstatus "failed"also generation_id
project.readyobject projectstatus "ready"also none (project_id equals id)
project.failedobject projectstatus "failed"also none (project_id equals id)
{
  "type": "generation.completed",
  "id": "evt_4b8c1d0e9f2a3b4c5d6e7f8091a2b3c4",
  "created_at": "2026-11-13T00:33:41Z",
  "data": {
    "object": "generation",
    "id": "ce832a32-a1ce-516a-b8bd-75457bd8517f",
    "project_id": "62f62565-049f-5e7e-bbd2-9de0cf7ddbfe",
    "end_user": "customer-42",
    "status": "complete",
    "kind": "restore"
  }
}
Reading generation and failure details
  • Generation id location: on all four generation.* events, the generation id is data.id (there is no generation_id field on generation payloads). On export.* and transcript_assistant_turn.* events, data.id is the export or turn id and data.generation_id names the generation.
  • Fetching media and errors: webhook payloads intentionally stay compact and never embed media URLs or human-readable error messages. On generation.completed, call GET /projects/{project_id}/generations/{generation_id}/media (or GET .../transcript). On generation.failed, data.error_code gives the machine-readable code; call GET /projects/{project_id}/generations/{generation_id} to inspect the full error object and warnings.

Verify signatures

Every webhook delivery is signed with Svix headers so you can verify authenticity and reject replay attacks. Always verify against the exact raw request body bytes (or string) before parsing JSON.

Required delivery headerssvix-idsvix-timestampsvix-signature

Verify with the Diffio SDK

Both SDKs verify signatures locally with zero external dependencies (default timestamp tolerance: 300 seconds) and return the parsed { type, id, created_at, data } event. In WebCrypto runtimes (Cloudflare Workers, Deno, Bun or browsers), call client.webhooks.verifySignatureAsync (or standalone verifyWebhookSignatureAsync). Python also exports standalone diffio.verify_webhook_signature.

import os

from diffio import DiffioClient, WebhookVerificationError

client = DiffioClient()
secret = os.environ["DIFFIO_WEBHOOK_SECRET"]  # the endpoint's whsec_... signing secret from the webhook portal


def handle_webhook(raw_body, headers):
    """raw_body: the request body bytes as received; headers: the request headers (any mapping)."""
    try:
        event = client.webhooks.verify_signature(raw_body, headers, secret)
    except WebhookVerificationError:
        return 400
    if event.type == "generation.completed":
        print("restored", event.data.project_id, event.data.id, event.data.end_user)
    elif event.type == "generation.failed":
        print("failed", event.data.id, event.data.error_code)
    return 200

Drop-in handlers

Each framework hides the raw body differently, and a parsed body never verifies. These read it the way the signature needs.

app/api/webhooks/diffio/route.ts
import { DiffioWebhookVerificationError, verifyWebhookSignatureAsync } from "diffio";

export async function POST(request: Request) {
  const rawBody = await request.text(); // read once, never request.json()
  try {
    const event = await verifyWebhookSignatureAsync(rawBody, request.headers, process.env.DIFFIO_WEBHOOK_SECRET!);
    // Record event.id and queue the work, then answer quickly.
    console.log(event.type, event.id, event.data.id);
    return new Response(null, { status: 204 });
  } catch (error) {
    if (error instanceof DiffioWebhookVerificationError) return new Response(null, { status: 400 });
    throw error;
  }
}

Verify by hand

If you do not use a Diffio SDK (or an official Svix library), verify the HMAC-SHA256 signature directly:

  1. Read svix-id, svix-timestamp (Unix seconds) and svix-signature from the headers, plus the raw body bytes.
  2. Reject the delivery if svix-timestamp is not an integer or differs from the current Unix time by more than 300 seconds.
  3. Strip the whsec_ prefix from your endpoint's signing secret and base64-decode the remaining string into raw key bytes.
  4. Compute HMAC-SHA256 over {svix-id}.{svix-timestamp}.{raw_body} using those key bytes, then base64-encode the digest.
  5. Split svix-signature on spaces; each entry has the form <version>,<digest>. Compare your digest in constant time against every v1, entry and accept if any matches.

Retries and recovery

Return any 2xx HTTP status code (such as 200OK. or 204No content.) as soon as signature verification succeeds, and hand downloads or database updates off to a background worker. Any non-2xx response or connection failure is retried automatically by Svix with backoff.

  • Deduplicate: Record event.id (evt_...) before running side effects. The event id is derived from the event type, resource and transition, so it stays identical across every automatic retry and manual redelivery.
  • Signature fails: Verify the raw body with the endpoint's own secret. Never pass JSON.stringify(req.body): re-serialized JSON changes bytes and breaks the HMAC (see drop-in handlers). Each endpoint has its own whsec_... secret, and timestamps more than 300 seconds from your clock are rejected.
  • Missed events: Inspect and resend deliveries in the webhook portal. Open a fresh portal link via POST /webhooks/portal to review attempt responses and trigger manual redeliveries.

Next steps

Report an issue with this page