# Webhooks

> Receive workspace events at your endpoint, verify signatures, and handle retries.

Webhooks send workspace events to an HTTPS endpoint you host as soon as they happen. Workspace owners and admins manage endpoints in the app under **Settings → Developers**, and members manage the test ones. Add a URL and copy the signing secret, which we show only once. Events then start arriving. You can edit an endpoint’s URL or events later, and it keeps the same signing secret.

## Managing endpoints through the API

Software can manage endpoints too, with a credential that has these scopes:

| To               | Scope                      |
| ---------------- | -------------------------- |
| Manage endpoints | `workspace.webhooks:write` |
| Read endpoints   | `workspace.webhooks:read`  |

**Manage limits** includes both.

With a personal access token, every member of the workspace can read endpoints. Owners and admins can add and change them, and members can add and change test endpoints. A test key can read endpoints but can’t add or change them. To manage them, use a live key (`lim_live_…`) or a personal access token. Each endpoint still belongs to either test or live, as described below.

```bash
curl -X POST \
  -H "Authorization: Bearer YOUR_LIVE_API_KEY" \
  -H "Idempotency-Key: $(uuidgen)" \
  -H "Content-Type: application/json" \
  -d '{ "url": "https://example.com/hooks" }' \
  https://api.limitry.com/v1/workspace/webhook-endpoints
```

The response is a `201` with the new endpoint. Its `Location` header holds the endpoint’s path. The endpoint’s signing secret is in `secret`, and the API returns it only this once:

```json
{
  "id": "we_3f0c1a2e-4b5d-4c6e-8f70-1a2b3c4d5e6f",
  "url": "https://example.com/hooks",
  "description": null,
  "enabled": true,
  "eventTypes": null,
  "environment": "live",
  "consecutiveFailures": 0,
  "lastHttpStatus": null,
  "lastAttemptAt": null,
  "createdAt": "2026-08-20T12:00:00.000Z",
  "secret": "whsec_MfKQ9r8GKYqrTwjUPD8ILPZIo2LaLaSw"
}
```

The API can also:

* list endpoints
* change an endpoint’s URL or events with `PATCH`, which keeps its secret
* re-enable an endpoint we switched off after repeated failures
* send a test event
* list deliveries and redeliver them

The [API reference](/docs/reference/) has every operation.

Sending a test event and redelivering answer `200` when we tried the delivery right away. Then `ok` and `httpStatus` say how your endpoint answered. They answer `202` when the delivery went to the queue, with `queued: true`. Redelivering to a disabled endpoint fails with `409` and the code `conflict`. Re-enable the endpoint first.

AI agents connected to the workspace can read endpoints and delivery history, send test events and redeliver. They can’t add, change, remove or re-enable endpoints, because that changes where your workspace’s data goes. Only a person can do that.

## A delivery

Each delivery is an HTTP `POST` with a JSON body:

```json
{
  "id": "evt_5f0c…",
  "type": "workspace.member.joined",
  "createdAt": "2026-08-20T12:00:00.000Z",
  "data": { "userId": "…", "email": "casey@example.com" }
}
```

Each delivery also carries three signature headers:

```http
webhook-id: del_9a1b…
webhook-timestamp: 1755691200
webhook-signature: v1,MEQCIB…
```

`webhook-id` identifies the delivery and stays the same when we retry it, so use it to ignore duplicates. The `id` in the body identifies the event.

If you have several endpoints, each gets its own delivery of the same event, so deduplicate by the event’s `id` to process it once. That also covers the rare case where an event reaches you more than once as separate deliveries, for example when we resend it after an outage.

## Verifying signatures

Before you trust a delivery, check that we sent it, that nobody changed it, and that it’s recent. The SDKs do all three checks with your endpoint’s secret (`whsec_…`) and give you the event:

* TypeScript

  ```ts
  import { verifyWebhook, WebhookVerificationError } from "@limitry/sdk";

  // A fetch-style handler (Hono, Workers, Next.js route handlers…).
  export async function POST(request: Request) {
    try {
      // The RAW body: verify before parsing it.
      const event = await verifyWebhook(
        await request.text(),
        request.headers,
        process.env.WEBHOOK_SECRET!,
      );
      // handle event…
      return new Response("ok");
    } catch (error) {
      if (error instanceof WebhookVerificationError) {
        return new Response("bad signature", { status: 400 });
      }
      throw error;
    }
  }
  ```

* Python

  ```python
  import os

  from flask import Flask, request
  from limitry import WebhookVerificationError, verify_webhook

  app = Flask(__name__)


  @app.post("/webhooks")
  def webhooks():
      try:
          # The RAW body: verify before parsing it.
          event = verify_webhook(
              request.get_data(), request.headers, os.environ["WEBHOOK_SECRET"]
          )
      except WebhookVerificationError:
          return "bad signature", 400
      # handle event…
      return "ok"
  ```

If you’ve already created a client, the same check is `limitry.webhooks.verify(…)`. The SDKs refuse a delivery older than 5 minutes, so no one can replay an old one. To change that limit, set `toleranceSeconds` in TypeScript or `tolerance_seconds` in Python.

We sign deliveries the same way [Svix](https://docs.svix.com/receiving/verifying-payloads/how) does, so any standard Svix library can verify them. In other languages, verify the signature yourself:

1. Take the secret without its `whsec_` prefix and Base64-decode it. That’s the HMAC key.
2. Compute the HMAC-SHA256 of `` `${webhookId}.${timestamp}.${body}` `` with that key, and Base64-encode it.
3. The signature is `v1,` followed by that value.

Always verify the **raw** body, because re-serialising the JSON changes it and breaks the signature. Reject timestamps more than a few minutes old.

## Respond quickly, process later

Respond with a `2xx` within 10 seconds, or the delivery counts as failed. If processing takes longer, acknowledge the delivery first and do the work afterwards.

## Retries and failures

If a delivery fails, we retry it with backoff, up to 6 attempts in total. Each retry keeps the same `webhook-id`. A delivery fails when your endpoint:

* times out
* doesn’t respond
* returns a `5xx`, `408` or `429`

Any other response, such as a `400` or a `404`, means your endpoint got the request and refused it. Retrying wouldn’t help, so that delivery fails straight away. We don’t follow redirects, so a `3xx` fails it too.

If 20 attempts in a row fail, across all of the endpoint’s deliveries, we switch the endpoint off. Once it’s working again, choose **Re-enable** under **Settings → Developers**, or call `POST /v1/workspace/webhook-endpoints/{endpointId}/enable`. It keeps its signing secret, and the count of failed attempts starts again from zero.

Under **Settings → Developers**, an endpoint’s **Deliveries** shows each delivery’s status and attempts. Through the API, a delivery’s `status` is its state: `pending`, `delivered` or `failed`. `lastHttpStatus` is the HTTP status code your endpoint last answered with. You can also send a test event (`type: "ping"`) and redeliver any recorded delivery. A redelivery gets a new `webhook-id` but keeps the event’s `id`, so deduplicating by event still works.

## Events

| Type                      | Sent when                                       | `data`                                                                                                                                 |
| ------------------------- | ----------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------- |
| `limit.threshold_crossed` | A subject first reaches 80% or 100% of a limit. | `limitId`, `limitName`, `action`, `unit`, `window`, `subject`, `environment`, `threshold`, `used`, `amount`, `periodStart`, `resetsAt` |
| `limit.reached`           | A limit first refuses a subject in a window.    | `limitId`, `limitName`, `action`, `unit`, `window`, `subject`, `environment`, `periodStart`, `resetsAt`                                |
| `workspace.member.joined` | Someone accepts an invitation.                  | `userId`, `email`                                                                                                                      |
| `ping`                    | You send a test from Settings.                  | a test message                                                                                                                         |

`limitName`, `action`, `unit` and `window` say what the limit is, so a handler can word its message (“80% of this month’s AI budget”) without looking the limit up.

An endpoint belongs to [test or live](/docs/test-and-live/#webhooks) and receives only that environment’s limit events. Both limit events also say which in `environment`, `"test"` or `"live"`. See [Usage and reports](/docs/usage/#webhook-limitreached) for an example.

### In the dashboard too

You don’t need a webhook to hear about your live limits. The dashboard tells the workspace’s owners and admins when a live limit refuses one of your users, and when one of your users passes 80% or 100% of a live limit. Each limit sends each notification at most once a day. Each person chooses whether it reaches them in the app, by email or on their phone. See [Notifications](/docs/notifications/).

## Warnings before a limit

`limit.threshold_crossed` tells you a subject is close to a limit while there’s still room to act: email the user, show a banner, offer more credits. Limitry sends it the first time a subject’s use reaches 80% of a limit in a window, and again at 100%, which is the last use the limit allows. Limitry refuses the first check after that and sends `limit.reached` as before.

```json
{
  "id": "evt_3c9a…",
  "type": "limit.threshold_crossed",
  "createdAt": "2026-10-08T09:14:02.000Z",
  "data": {
    "limitId": "lmt_…",
    "limitName": "AI budget",
    "action": "ai-call",
    "unit": "cents",
    "window": "month",
    "subject": { "kind": "user", "id": "user_123" },
    "environment": "live",
    "threshold": 80,
    "used": 160,
    "amount": 200,
    "periodStart": "2026-10-01T00:00:00.000Z",
    "resetsAt": "2026-11-01T00:00:00.000Z"
  }
}
```

How often each kind of limit warns:

| Limit                                      | When it warns                                                                                                                                                                                                      |
| ------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| Per minute, hour, day, week, month or year | Once at 80% and once at 100% in each window.                                                                                                                                                                       |
| Rolling (“in any 24 hours”)                | At 80% and 100%, at most once an hour for each.                                                                                                                                                                    |
| Balance (window `total`)                   | At 20% left (`threshold: 80`) and when it runs out (`threshold: 100`). After you add credits, it can warn again (as a new event, with a new id) as the balance runs down. `periodStart` and `resetsAt` are `null`. |
| Concurrent (“at most N at once”)           | Never. A concurrent limit fills and empties all the time, so a warning would mean nothing.                                                                                                                         |

A warning reaches your endpoint within about a minute of the check that crossed the line. A [reservation](/docs/reservations/) counts from the moment you make it. If its commit costs more than it reserved, the extra use can warn too. If you release a reservation that warned, or commit it for less, the warning stands. The next time use reaches the line, it warns again. A rolling limit still warns at most once an hour.

A warning from [test](/docs/test-and-live/) carries `"environment": "test"`, so a handler can skip it. If we send the same warning twice, after an outage for example, both deliveries carry the same event `id`, so deduplicating by `id` drops the second one.

Limitry only tells you. Whether and how to tell your user is up to your product: see [Warn your users before they hit a limit](/docs/guides/warn-users/).

Event payloads only ever gain fields, so write parsers that ignore fields they don’t know. `GET /v1/workspace/event-types` lists every event type and what it means.

## Choosing events

An endpoint receives every event unless you choose otherwise. In **Settings → Developers**, pick “Only these” when you add the endpoint. Through the API, pass `eventTypes` when you create it:

```bash
curl -X POST https://api.limitry.com/v1/workspace/webhook-endpoints \
  -H "Authorization: Bearer YOUR_LIVE_API_KEY" -H "content-type: application/json" \
  -d '{"url":"https://example.com/hooks","eventTypes":["limit.reached"]}'
```

A test event (`ping`) always reaches the endpoint you’re testing.
