# Webhooks

> For the complete documentation index, see [llms.txt](https://www.shortsintel.com/llms.txt). Every docs page is also available as markdown: add .md to its URL. To connect, read [agents.md](https://www.shortsintel.com/agents.md).

> The events we send, how to verify a signature, what happens when your endpoint is down, and how to rotate a secret.

- Price: Webhooks are never charged. Registering an endpoint: Free.
- Events: `run.completed` and `tracker.changed` reach every active endpoint. `webhook.test` is sent once, at registration.
- Signature: HMAC-SHA256 in `X-ShortsIntel-Signature`. Reject deliveries older than 300 seconds.
- Retries: 3 attempts, the last about 1 hour after the event. Nothing is re-sent after that.
- Endpoints: Up to 5 at once, `https` only.

A webhook tells you the moment work finishes, so you do not have to poll. We POST a small signed JSON body to your HTTPS URL, retry it if your server is down, and log every delivery.

## A webhook pushes a signed event when work finishes

When a Run settles or a Tracker reports a change, we send an event to your endpoint. A Run is the record of one charged call, with its status, cost and result. A Tracker is a watch on a creator, hashtag, keyword, sound or advertiser that runs on a schedule.

## Every active endpoint gets both event types

| Event | When it is sent |
| --- | --- |
| `run.completed` | A Run reached a terminal state. `completed`, `partial` and `failed` all use this one type, so branch on `status`. |
| `tracker.changed` | A Tracker cycle wrote a Change Report. Quiet cycles send nothing. It carries the Tracker's `collections` by id and name, for routing. |
| `webhook.test` | The handshake sent when you register an endpoint. A 2xx answer activates the endpoint. |

There is no subscription list. An active endpoint gets both of them for your Customer, so branch on `type` and ignore what you do not handle. `webhook.test` is sent only once, when you register.

## When to use a webhook

Use a webhook when a server should react to finished work without polling: a long Run such as a research, or a Tracker that changes between your visits. For one call you are waiting on now, polling the Run is simpler. See [Runs](https://www.shortsintel.com/docs/concepts/runs).

## How a delivery works

1. You register an endpoint. A `2xx` answer to `webhook.test` makes it `active`.
2. A Run settles or a Tracker reports a change.
3. We POST the event, signed with your secret.
4. You verify the raw body and answer 2xx fast.
5. We retry a failed attempt, re-signed each time.
6. You read the log and replay what you missed.

## Register an endpoint after your receiver is live

Registration is also the handshake. We send `webhook.test` to the URL at once, and the endpoint becomes `active` only if your server answers `2xx`. Anything else leaves it `failed`, and a failed endpoint receives nothing until you delete it and register it again. Deploy your receiver first.

`POST /v1/webhooks` · Free.

curl:

```bash
curl -X POST "https://www.shortsintel.com/v1/webhooks" \
  -H "Authorization: Bearer sk_live_YOUR_KEY" \
  -H "Content-Type: application/json" \
  -d '{"url":"https://example.com/hooks/shortsintel","description":"Production listener"}'
```

TypeScript:

```typescript
const response = await fetch(
  "https://www.shortsintel.com/v1/webhooks",
  {
    method: "POST",
    headers: {
      "Authorization": "Bearer sk_live_YOUR_KEY",
      "Content-Type": "application/json",
    },
    body: JSON.stringify({
      "url": "https://example.com/hooks/shortsintel",
      "description": "Production listener"
    }),
  },
);

if (!response.ok) {
  throw new Error(`ShortsIntel ${response.status}`);
}

const data = await response.json();
```

Python:

```python
import requests

response = requests.post(
    "https://www.shortsintel.com/v1/webhooks",
    headers={
        "Authorization": "Bearer sk_live_YOUR_KEY",
        "Content-Type": "application/json",
    },
    json={
        "url": "https://example.com/hooks/shortsintel",
        "description": "Production listener",
    },
)
response.raise_for_status()

data = response.json()
```

201 · `{ webhook, secret, test_delivery }`.

```json
{
  "webhook": {
    "id": "whe_6d2f10ab44",
    "url": "https://hooks.example.com/shortsintel",
    "status": "active",
    "description": "production receiver",
    "secret_prefix": "whsec_a1b2c3",
    "previous_secret_expires_at": null,
    "created_at": "2026-09-08T09:14:02.418Z",
    "activated_at": "2026-09-08T09:14:03.006Z",
    "last_delivery_at": "2026-09-08T09:14:03.006Z"
  },
  "secret": "whsec_9Qk3Tn7f2xLd0aZmVbYpRc8sHu6WjEg4",
  "test_delivery": {
    "id": "whd_51c8b0f7e3",
    "event_id": "evt_kZ8Qw3n1TfLd0aZmVbYpRc",
    "event_type": "webhook.test",
    "status": "delivered",
    "attempts": 1,
    "response_status": 200,
    "error": null,
    "run_id": null,
    "tracker_id": null,
    "change_report_id": null,
    "replay_of": null,
    "created_at": "2026-09-08T09:14:02.911Z",
    "last_attempt_at": "2026-09-08T09:14:03.006Z",
    "delivered_at": "2026-09-08T09:14:03.006Z",
    "failed_at": null
  }
}
```



> **Warning:** The `secret` in that response is shown once, and no endpoint returns it again. Store it before you close the connection. `secret_prefix` tells two secrets apart but cannot verify.

URLs must be `https` and must not resolve into a private range: no `localhost`, no `10.x`, no `169.254.169.254`. The check runs at registration and again before every attempt, because a public hostname can later resolve elsewhere. Redirects are not followed. You may hold 5 endpoints at once.

## The payload carries ids and links, not results

An event names what happened and links to it, without the results. A small body is cheap to sign and cannot disclose more than your key may already read. Fetch the results with your own key.

```json
{
  "id": "evt_9tR2kPq7wXsL4mVb",
  "type": "tracker.changed",
  "created_at": "2026-09-12T08:00:00.000Z",
  "run_id": "run_c07a41bb92",
  "kind": "tracker_cycle",
  "status": "completed",
  "charge_credits": 50,
  "tracker_id": "trk_4b1e90c7aa",
  "change_report_id": "chg_2ac910f4d8",
  "collections": [
    {
      "id": "col_7d20e1b5c4",
      "name": "Competitors"
    }
  ],
  "links": {
    "run": "https://www.shortsintel.com/v1/runs/run_c07a41bb92",
    "tracker": "https://www.shortsintel.com/v1/trackers/trk_4b1e90c7aa",
    "changes": "https://www.shortsintel.com/v1/trackers/trk_4b1e90c7aa/changes"
  }
}
```

Three headers come with it: `X-ShortsIntel-Signature`, `X-ShortsIntel-Event-Id` and `X-ShortsIntel-Event-Type`. The event id is the same across retries and replays, so deduplicate on it.

The event id and type headers repeat the body’s `id` and dotted `type`, so you can route and deduplicate without parsing the body. Each delivery is a POST with `Content-Type: application/json` and `User-Agent: ShortsIntel-Webhooks/1`.

## Verifying a signature

The signature header carries a timestamp `t` and one or more hex HMACs. Each `v1` is HMAC-SHA256, keyed with your secret, over `"<t>.<body>"`: the unix timestamp, a literal dot, then the raw body bytes. The timestamp is signed, so a captured delivery cannot be replayed at you later.

Three rules decide whether a verifier is correct:

| Rule | Why |
| --- | --- |
| Sign the raw body | `JSON.stringify(req.body)` never matches. |
| Compare in constant time | A plain comparison leaks timing. |
| Accept any matching `v1` | During a secret rotation there are two. |



```typescript
import { createHmac, timingSafeEqual } from "node:crypto";

const TOLERANCE_SECONDS = 300;

/** Pass the RAW request body, exactly as it arrived, not a re-serialised object. */
export function verify(header: string | null, body: string, secret: string) {
  if (!header) return false;

  let timestamp: number | null = null;
  const signatures: string[] = [];
  for (const part of header.split(",")) {
    const [key, value] = part.trim().split("=", 2);
    if (!value) continue;
    if (key === "t") timestamp = Number(value);
    else if (key === "v1") signatures.push(value);
  }
  if (timestamp === null || !Number.isInteger(timestamp)) return false;
  if (signatures.length === 0) return false;

  const now = Math.floor(Date.now() / 1000);
  if (Math.abs(now - timestamp) > TOLERANCE_SECONDS) return false;

  const expected = Buffer.from(
    createHmac("sha256", secret).update(`${timestamp}.${body}`, "utf8").digest("hex"),
    "hex",
  );

  // Any v1 matching is a pass: during a secret rotation there are two.
  return signatures.some((candidate) => {
    const got = Buffer.from(candidate, "hex");
    return got.length === expected.length && timingSafeEqual(got, expected);
  });
}
```



```python
import hashlib
import hmac
import time

TOLERANCE_SECONDS = 300


def verify(header: str | None, body: bytes, secret: str) -> bool:
    """Pass the RAW request body, exactly as it arrived."""
    if not header:
        return False

    timestamp = None
    signatures = []
    for part in header.split(","):
        key, _, value = part.strip().partition("=")
        if not value:
            continue
        if key == "t":
            timestamp = int(value)
        elif key == "v1":
            signatures.append(value)

    if timestamp is None or not signatures:
        return False
    if abs(int(time.time()) - timestamp) > TOLERANCE_SECONDS:
        return False

    signed = f"{timestamp}.".encode() + body
    expected = hmac.new(secret.encode(), signed, hashlib.sha256).hexdigest()

    # Any v1 matching is a pass: during a secret rotation there are two.
    return any(hmac.compare_digest(candidate, expected) for candidate in signatures)
```

Reject a `t` more than 300 seconds from your clock, in either direction. That is the tolerance we publish. A wider window gives an attacker room to replay, and a narrower one breaks on ordinary clock drift.

## Failed deliveries retry, then stay failed

Each attempt is a POST with a 10 second timeout. Only a `2xx` acknowledges an event. A `3xx` is not followed, and anything else is a failure. Answer first and work afterwards: a receiver that processes before it replies times out and gets the event again.

A failed attempt is retried, 3 attempts in all: immediately, then about 10 minutes and about 60 minutes after the first, so the last lands about 1 hour after the event. Each attempt is re-signed with a fresh timestamp, so a late retry still passes the freshness check.

After the last attempt the delivery is `failed`. Your endpoint stays enabled, but nothing is re-sent on its own. `GET /v1/webhooks/{id}/deliveries` is the log: one row per delivery, with how many attempts it took, your last status code and any error.

200 · `{ items, next_cursor }`.

```json
{
  "items": [
    {
      "id": "whd_51c8b0f81a",
      "event_id": "evt_pR4Vm8s2XqNb7cTfKdYw1E",
      "event_type": "run.completed",
      "status": "failed",
      "attempts": 3,
      "response_status": 503,
      "error": "receiver returned 503",
      "run_id": "run_8f2c1ad04b",
      "tracker_id": null,
      "change_report_id": null,
      "replay_of": null,
      "created_at": "2026-09-08T09:14:02.911Z",
      "last_attempt_at": "2026-09-08T09:14:03.006Z",
      "delivered_at": null,
      "failed_at": "2026-09-08T09:41:10.220Z"
    },
    {
      "id": "whd_51c8b0f7e3",
      "event_id": "evt_kZ8Qw3n1TfLd0aZmVbYpRc",
      "event_type": "webhook.test",
      "status": "delivered",
      "attempts": 1,
      "response_status": 200,
      "error": null,
      "run_id": null,
      "tracker_id": null,
      "change_report_id": null,
      "replay_of": null,
      "created_at": "2026-09-08T09:14:02.911Z",
      "last_attempt_at": "2026-09-08T09:14:03.006Z",
      "delivered_at": "2026-09-08T09:14:03.006Z",
      "failed_at": null
    }
  ],
  "next_cursor": null
}
```

## Replay a delivery your endpoint missed

Once your endpoint is healthy, `POST /v1/webhooks/{id}/deliveries/{deliveryId}/replay` queues a new delivery with the same event id and body. Free.

202 · `{ delivery }`, queued.

```json
{
  "delivery": {
    "id": "whd_51c8b0f9c0",
    "event_id": "evt_pR4Vm8s2XqNb7cTfKdYw1E",
    "event_type": "run.completed",
    "status": "pending",
    "attempts": 0,
    "response_status": null,
    "error": null,
    "run_id": "run_8f2c1ad04b",
    "tracker_id": null,
    "change_report_id": null,
    "replay_of": "whd_51c8b0f81a",
    "created_at": "2026-09-08T10:02:00.000Z",
    "last_attempt_at": null,
    "delivered_at": null,
    "failed_at": null
  }
}
```

Because the event id is the same, a receiver that did process the original drops the replay as a duplicate. The replay carries a fresh signature. A delivery still being attempted cannot be replayed.

## Rotate a secret without dropping events

`POST /v1/webhooks/{id}/rotate` mints a new signing secret and shows it once. The old one keeps working for 24 hours. In that window every delivery is signed with both: one `t` and two `v1` values over the same body.

200 · `{ webhook, secret, overlap_expires_at }`, with `secret` shown once.

```json
{
  "webhook": {
    "id": "whe_6d2f10ab44",
    "url": "https://hooks.example.com/shortsintel",
    "status": "active",
    "description": "production receiver",
    "secret_prefix": "whsec_d4e5f6",
    "previous_secret_expires_at": "2026-09-09T09:14:02.418Z",
    "created_at": "2026-09-08T09:14:02.418Z",
    "activated_at": "2026-09-08T09:14:03.006Z",
    "last_delivery_at": "2026-09-08T09:14:03.006Z"
  },
  "secret": "whsec_Lm2Rv8ZaQe5tYb1nXc7pKd3sWu9jHg6F",
  "overlap_expires_at": "2026-09-09T09:14:02.418Z"
}
```

The new secret’s `v1` comes first. A verifier that accepts any matching `v1` needs no change. Rotating again while an overlap is open returns `409`.

`DELETE /v1/webhooks/{id}` stops delivery and frees a slot. The endpoint is tombstoned, not erased, so its delivery history stays readable. Nothing about webhooks is charged. See [Trackers](https://www.shortsintel.com/docs/concepts/trackers) for what sends a `tracker.changed`.

## Limits

| Limit | Value |
| --- | --- |
| Endpoints at once | 5 |
| Attempt timeout | 10 seconds |
| Attempts per delivery | 3 |
| Retry spacing | About 10 and 50 minutes |
| Signature tolerance | 300 seconds |
| Old secret after a rotation | 24 hours |

## Example: check a signed tracker.changed delivery

The bytes on the wire are compact, not pretty-printed. This raw body is what the HMAC covers:

```text
{"id":"evt_9tR2kPq7wXsL4mVb","type":"tracker.changed","created_at":"2026-09-12T08:00:00.000Z","run_id":"run_c07a41bb92","kind":"tracker_cycle","status":"completed","charge_credits":50,"tracker_id":"trk_4b1e90c7aa","change_report_id":"chg_2ac910f4d8","collections":[{"id":"col_7d20e1b5c4","name":"Competitors"}],"links":{"run":"https://www.shortsintel.com/v1/runs/run_c07a41bb92","tracker":"https://www.shortsintel.com/v1/trackers/trk_4b1e90c7aa","changes":"https://www.shortsintel.com/v1/trackers/trk_4b1e90c7aa/changes"}}
```



```text
X-ShortsIntel-Signature: t=1789200000,v1=f65c1154b65cea2019d07485d3d7db08f14a3d9c2c77436f7ca4841442d775b3
```

That header is the real signature of those bytes under the secret `whsec_EXAMPLE_SECRET_REPLACE_ME`. Pass them to either verifier above, with the clock check relaxed because the timestamp is fixed, and it returns true.

## Questions about Webhooks

### Why does my signature never match?

You are almost certainly signing a re-serialised object. Sign the raw request body, exactly as it arrived, prefixed with the timestamp and a dot.

### What happens when my endpoint is down?

After 3 attempts the delivery is `failed`. Replay it once you are back.

### Do webhooks cost Credits?

No. Credits are the unit you prepay into your Balance, and registering, deliveries, replays and rotations spend none.

### Can I get the secret again?

No. It is shown once at registration or rotation. If you lose it, rotate to mint a new one.
