Docs / Getting Started

Quickstart

Install the official TypeScript (@kestrelmq/sdk) or Python (kestrelmq) SDK, send your first event, and verify signed outbound webhooks with zero-downtime secret rotation.

Updated 2026-12-03~5 min readTypeScript · Python · cURL

KestrelMQ has two official SDKs: @kestrelmq/sdk for TypeScript (npm) and kestrelmq for Python (PyPI). Both wrap the same REST API, so plain curl works too. Pick a language once and every tab on this page follows it.

You need a kmq_live_ API key: create one under API Keys in the dashboard, or follow Self-Hosted Onboarding. Don't have a server yet? Self-host in 5 minutes with ./scripts/selfhost-up.sh.

1. Install the SDK

terminal
npm install @kestrelmq/sdk

Zero runtime dependencies, ESM only, Node.js >=22.12.

Set the API key and base URL. Self-hosted stacks started with selfhost-up.sh listen on http://localhost:8080:

.env
KESTRELMQ_API_KEY=kmq_live_...
KESTRELMQ_BASE_URL=http://localhost:8080

The Python client reads both variables automatically. The base URL may include or omit /v1.

2. Send an event

POST /v1/events validates the payload, locks the Idempotency-Key, fans the event out through your routing rules and returns 202 Accepted.

checkout.service.ts
import { KestrelClient } from "@kestrelmq/sdk";

const kestrel = new KestrelClient({
  baseUrl: process.env.KESTRELMQ_BASE_URL!,
  apiKey: process.env.KESTRELMQ_API_KEY!,
});

const receipt = await kestrel.events.send({
  event: "order.paid",
  payload: { orderId: "ord_9812", amount: 4900 },
  idempotencyKey: "order-paid-ord_9812",
});

console.log(receipt.eventId, receipt.deliveryIds);
202 Accepted
{
  "eventId": "2b6f0c1d-4e5a-4b6e-9c0e-2f6a1f3c9a10",
  "eventName": "order.paid",
  "workspaceId": "6f0c1d4e-5a52-4b6e-9c0e-2f6a1f3c9a10",
  "idempotencyKey": "order-paid-ord_9812",
  "idempotentReplay": false,
  "scheduledFor": null,
  "schemaWarnings": null,
  "deliveryIds": ["9bafef5c-41d2-4e89-9a0b-3c14d78e02f1"],
  "deliveries": [
    {
      "id": "9bafef5c-41d2-4e89-9a0b-3c14d78e02f1",
      "routingRuleId": "c1a2b3d4-5e6f-4a1b-8c9d-0e1f2a3b4c5d",
      "integrationId": "d4c3b2a1-6f5e-4b1a-9d8c-5c4b3a2f1e0d",
      "status": "PENDING",
      "scheduledFor": null
    }
  ]
}

Repeating the same Idempotency-Key returns the original event with idempotentReplay: true and creates no new deliveries. Errors are RFC 9457 Problem Details: KestrelApiError in TypeScript, KestrelAPIError in Python.

3. Verify outbound webhook signatures

Every webhook attempt carries X-KestrelMQ-Timestamp and X-KestrelMQ-Signature: v1=<hex>, an HMAC-SHA256 of "{timestamp}.{rawBody}" keyed with your workspace signing secret. Both SDKs ship a constant-time verifier that rejects timestamps more than 300 seconds off.

Zero-downtime secret rotation

After POST /v1/workspaces/:id/rotate-secret, KestrelMQ signs every attempt with both secrets for the grace window and sends X-KestrelMQ-Signature: v1=<new>,v1=<old>. Both verifiers accept the request if any v1= entry matches, so receivers holding the old secret keep working while you deploy the new one.

app/api/webhooks/kestrelmq/route.ts
import { verifyWebhookSignature } from "@kestrelmq/sdk";

export const runtime = "nodejs";

export async function POST(request: Request) {
  const payload = await request.text(); // raw body, before JSON.parse

  const ok = verifyWebhookSignature({
    payload,
    signatureHeader: request.headers.get("x-kestrelmq-signature") ?? "",
    timestamp: request.headers.get("x-kestrelmq-timestamp") ?? undefined,
    secret: process.env.KESTRELMQ_SIGNING_SECRET!,
  });
  if (!ok) return new Response("invalid signature", { status: 401 });

  const event = JSON.parse(payload);
  // ...deduplicate on X-KestrelMQ-Delivery-Id, then process
  return new Response(null, { status: 204 });
}

verifyWebhookSignature takes one secret and checks it against every v1= entry, so the old secret keeps verifying during the grace window.

Always verify the raw body: parsing and re-serializing JSON changes the bytes and breaks the signature. KestrelMQ is at-least-once, so deduplicate on X-KestrelMQ-Delivery-Id.

Interactive Verify Signature snippets

Open any webhook delivery in the dashboard Delivery Inspector and switch to Verify Signature to copy a ready-to-run Node.js, Python, or Go verification snippet populated with that attempt's x-kestrelmq-signature, x-kestrelmq-timestamp, and raw request body.

4. Test delivery with the Echo Sandbox

You don't need external webhook.site request bins or local tunnels (ngrok, cloudflared) to test webhook delivery, retries, DLQ routing, or HMAC signatures. Every workspace includes a built-in Echo Sandbox receiver at /v1/sandbox/sink/:workspaceId (with an optional /:mode path segment or ?simulate= query parameter):

Echo Sandbox endpoints
{API_ORIGIN}/v1/sandbox/sink/:workspaceId            # uses workspace mode (default 200)
{API_ORIGIN}/v1/sandbox/sink/:workspaceId/200        # 200 OK -> DELIVERED
{API_ORIGIN}/v1/sandbox/sink/:workspaceId/500        # 500 Internal Server Error -> RETRYING -> FAILED (DLQ)
{API_ORIGIN}/v1/sandbox/sink/:workspaceId/429        # 429 Too Many Requests + Retry-After: 5 -> RETRYING
{API_ORIGIN}/v1/sandbox/sink/:workspaceId/timeout    # holds 12s (exceeds 10s worker timeout) -> RETRYING

In the dashboard, click Test with Echo Sandbox on Deliveries (or Create Sandbox Endpoint under Routing Rules), or wire the sink via the REST API:

terminal
# 1. Point a webhook integration at the built-in 500 sink (or ?simulate=500)
curl -s -X POST "$KESTRELMQ_BASE_URL/v1/integrations" \
  -H "Authorization: Bearer $ACCESS_TOKEN" \
  -H "X-Workspace-Id: $WORKSPACE_ID" \
  -H "Content-Type: application/json" \
  -d "{
    \"name\": \"Echo Sandbox\",
    \"channel\": \"WEBHOOK\",
    \"provider\": \"CUSTOM_WEBHOOK\",
    \"credentials\": { \"url\": \"$KESTRELMQ_BASE_URL/v1/sandbox/sink/$WORKSPACE_ID/500\" }
  }"

Every request received by the sink returns diagnostic JSON (receivedAt, method, headers, body, signatureValid) and is stored in the last-20 live log (GET /v1/sandbox/sink/:workspaceId/requests):

200 OK · Echo Sandbox diagnostic response
{
  "receivedAt": "2026-12-03T12:00:01.142Z",
  "method": "POST",
  "headers": {
    "content-type": "application/json",
    "user-agent": "KestrelMQ-Webhook/1.0",
    "x-kestrelmq-timestamp": "1764763201",
    "x-kestrelmq-signature": "v1=9c4e2b8f01d7a63e54b109c8a72f6d41e80b3c529a14f7d603e8b2c1a490f512"
  },
  "body": { "orderId": "ord_9812", "amount": 4900 },
  "signatureValid": true
}

With BACKOFF_SCALE_FACTOR=0.01 on a local worker, all 5 retry attempts finish in seconds so you can watch PENDING → PROCESSING → RETRYING → FAILED (deliveries-dlq), switch the sink to 200, and replay the delivery. See Testing Webhooks for full details.

Next steps