Skip to main content

Reference

Webhooks

Event-driven integrations for async operations

6 min read


KLOAKD can call your server in two ways:

  • Organization webhooks: endpoints your organization registers once, in the dashboard (Settings → Webhooks). They receive your organization's job events, and every delivery is signed.
  • Per-job webhooks: a webhook_url you pass when you start an async fetch. KLOAKD notifies it when that job ends. These calls are not signed.

Organization webhooks

Who can change them

Only organization admins and owners, signed in to the dashboard, can add, change, delete or test a webhook, or rotate its secret. Members and API keys can list and read webhooks, but cannot change them.

Adding a webhook

Give the webhook a name, a URL and the events it subscribes to. You may add up to 20 custom headers, for example a token your receiver checks.

The URL must be an http or https address on the public internet. URLs that name or resolve to a private, loopback, link-local or cloud-metadata address, or localhost, are refused when you save them. A name that later resolves to such an address is refused when KLOAKD delivers.

Custom headers cannot replace the headers KLOAKD sets itself or those that frame the request: Host, Content-Length, Content-Type, Content-Encoding, Transfer-Encoding, Connection, Keep-Alive, Proxy-Authorization, Proxy-Connection, TE, Trailer, Upgrade, User-Agent and X-Webhook-Signature.

The signing secret

Every organization webhook has a signing secret. KLOAKD generates one when you create the webhook, or you can supply your own (16 to 255 characters).

The secret is shown once: in the response that creates the webhook, and again only when you rotate it. Copy it to your receiver straight away. Afterwards the dashboard and the API show *** in its place.

Rotate secret gives the webhook a new secret, shown once. The old secret stops working at once: every delivery after that is signed with the new one, so update your receiver first.

Custom header values are hidden too: reads show the header names with the value ***. When you update a webhook, sending *** as a header's value keeps the stored value.

A webhook that has no secret (one created before secrets were required) receives nothing until you give it one with Add a secret.

Verifying a delivery

Each delivery is a POST with these headers, plus your custom headers:

| Header | Value | |--------|-------| | Content-Type | application/json | | User-Agent | Kobe-Scraper-Webhook/1.0 | | X-Webhook-Signature | sha256=<hex>: the HMAC-SHA256 of the raw request body, keyed with the webhook's secret |

Compute the HMAC over the raw bytes of the body, before you parse the JSON, and compare it with the header in constant time:

import hashlib
import hmac

def is_from_kloakd(raw_body: bytes, signature_header: str, secret: str) -> bool:
    expected = "sha256=" + hmac.new(secret.encode(), raw_body, hashlib.sha256).hexdigest()
    return hmac.compare_digest(expected, signature_header or "")
import { createHmac, timingSafeEqual } from 'node:crypto';

function isFromKloakd(rawBody: Buffer, signatureHeader: string, secret: string): boolean {
  const expected = Buffer.from(
    'sha256=' + createHmac('sha256', secret).update(rawBody).digest('hex'),
  );
  const received = Buffer.from(signatureHeader ?? '');
  return expected.length === received.length && timingSafeEqual(expected, received);
}

The signature covers the body only. To ignore a delivery replayed later, reject a delivery_id you have already seen, or a timestamp that is too old.

Delivery body

{
  "delivery_id": "0b6f3a8e-5d3c-4c1e-9a0f-2b7d9e4c1a55",
  "event_type": "job.completed",
  "payload": {
    "completed_at": "2026-11-11T10:15:30.123456+00:00",
    "job_id": "5f0c7f9e-0d6b-4d0e-9a52-6a1d3c1e2b47",
    "job_name": "Product pages",
    "results_count": 12,
    "status": "completed"
  },
  "timestamp": "2026-11-11T10:15:30.456789",
  "webhook_id": "8d2e6c1b-3f4a-4b5c-8d9e-0a1b2c3d4e5f"
}

timestamp is when the delivery was made, in UTC.

Events

You can subscribe to job.started, job.completed, job.failed, scraper.created, scraper.updated, scraper.deleted, batch.started, batch.completed and batch.failed.

Today KLOAKD sends job.completed, when a scraping job finishes. You can subscribe to the other events now, but they are not sent yet.

Testing a webhook

Send test in the dashboard (or POST /api/v1/organizations/{org_id}/webhooks/{webhook_id}/test with an event_type) queues a signed delivery whose payload is a test message ("test": true). The webhook must be active and subscribed to that event.

Responding

Answer with any 2xx status within the webhook's timeout (30 seconds unless you set another, from 1 to 300). Redirects are not followed: a 3xx counts as a failed delivery. Each event is delivered once; a failed delivery is not retried for you. An admin or owner can read a delivery with its payload (GET /api/v1/organizations/{org_id}/webhooks/{webhook_id}/deliveries/{delivery_id}) and send it again (POST …/deliveries/{delivery_id}/retry): the payload and delivery_id are the original's, so your receiver can recognise the duplicate, the timestamp and signature are new, and the attempt is recorded as a new delivery with the next attempt_number.

Per-job webhooks (webhook_url)

KLOAKD can tell your server when an async fetch ends: pass a webhook_url when you start it. The webhook is a notification: it names the job and its outcome, not the page. Collect the result from poll_url with your API key.

Receive fetch completion via webhook

Pass a webhook_url (an https URL on the public internet) to evadr.fetch_async():

job_id = client.evadr.fetch_async(
    "https://example.com",
    webhook_url="https://your-server.com/webhooks/kloakd",
)
const jobId = await client.evadr.fetchAsync('https://example.com', {
  webhookUrl: 'https://your-server.com/webhooks/kloakd',
});

Webhook payload

When the job ends, KLOAKD sends a POST with a JSON body:

{
  "event": "evadr.fetch.completed",
  "job_id": "5f0c7f9e-0d6b-4d0e-9a52-6a1d3c1e2b47",
  "status": "completed",
  "url": "https://example.com",
  "success": true,
  "status_code": 200,
  "error": null,
  "poll_url": "/api/v1/organizations/{org_id}/evadr/jobs/5f0c7f9e-0d6b-4d0e-9a52-6a1d3c1e2b47"
}

When the job itself failed, the body has no status_code:

{
  "event": "evadr.fetch.failed",
  "job_id": "5f0c7f9e-0d6b-4d0e-9a52-6a1d3c1e2b47",
  "status": "failed",
  "url": "https://example.com",
  "success": false,
  "error": "…",
  "poll_url": "/api/v1/organizations/{org_id}/evadr/jobs/5f0c7f9e-0d6b-4d0e-9a52-6a1d3c1e2b47"
}

A completed job can still carry success: false (the page could not be fetched; status_code is then 0 and error says why).

Headers: Content-Type: application/json, User-Agent: KLOAKD-Webhook/1, and X-Kloakd-Event (the event name).

Event types

| Event | When | |-------|------| | evadr.fetch.completed | The async fetch finished (success says whether the page was fetched) | | evadr.fetch.failed | The job itself failed (error says why) |

For crawl operations, use client.crawl_stream() or client.webgrph.crawl_stream() for real-time SSE progress instead of webhooks. Streaming gives you per-page events as they happen.

Trusting a per-job webhook

Per-job webhooks are not signed. They carry no page data, so treat one only as a signal: fetch the result from poll_url with your API key, which is authenticated. A forged webhook then gains nothing.

Responding to per-job webhooks

Answer with any 2xx within 10 seconds. KLOAKD tries up to 3 times (immediately, then after 2 and 10 seconds). Redirects are followed, but a URL that is not https, or that leads to a private or internal address, is refused when you start the job (422) or when delivering.

# FastAPI example
from fastapi import FastAPI, Request
from kloakd import Kloakd

app = FastAPI()
client = Kloakd(api_key="sk-live-...", organization_id="...")

@app.post("/webhooks/kloakd")
async def kloakd_webhook(request: Request):
    event = await request.json()
    if event["event"] == "evadr.fetch.completed":
        job = client.evadr.get_job(event["job_id"])  # authenticated: the real result
        print(job["status"], job.get("result", {}).get("status_code"))
    return {"ok": True}
Was this page helpful?