> ## Documentation Index
> Fetch the complete documentation index at: https://docs.hotkey.so/llms.txt
> Use this file to discover all available pages before exploring further.

# Webhooks

> Get a signed POST the moment an ask starts or ends, a download finishes or a browser wakes.

A webhook endpoint is an https address of yours. Hotkey POSTs every event of the types you pick there, for every browser in the workspace of the key that made it. Each POST carries one [event](https://docs.hotkey.so/api.md#events), the same object that `GET /v1/events` returns.

## Make an endpoint

```bash theme={null}
curl https://console.hotkey.so/v1/webhook_endpoints \
  -H "Authorization: Bearer $HOTKEY_KEY" -H "content-type: application/json" \
  -d '{ "url": "https://example.com/hotkey", "events": ["ask.*", "download.finished"] }'
```

```json theme={null}
{ "id": "we_Xk29bQp0c7LmA1sZ", "object": "webhook_endpoint", "url": "https://example.com/hotkey",
  "events": ["ask.*", "download.finished"], "description": null, "created": "…", "last_delivery": null,
  "secret": "whsec_…" }
```

The `secret` is shown only here. Keep it to check signatures.

* `events` lists the types to send. A type can be exact (`ask.done`), a group (`ask.*`), or `"*"` for every type.
* `workspace.*` events are about the workspace, not a browser: its plan changed, a payment failed, Free's hours ran out ([the types](https://docs.hotkey.so/api.md#events)). Their `browser` is null, and an endpoint made for one browser doesn't get them.
* A workspace has at most 10 endpoints, on every plan, Free included ([Plans and limits](https://docs.hotkey.so/limits.md#plans)).
* The address must use https, and resolve to a public address.
* In a team, every member sees the team's endpoints. A member changes and deletes the endpoints they made, and owners and admins any of them (403 `role_too_low` otherwise). When a member leaves or is removed, the endpoints they made for the team are deleted with their keys.

Also available:

* `GET /v1/webhook_endpoints` lists your endpoints, and `GET /v1/webhook_endpoints/{id}` shows one, with its `last_delivery`.
* `PATCH /v1/webhook_endpoints/{id}` changes `url`, `events` or `description`.
* `DELETE /v1/webhook_endpoints/{id}` deletes an endpoint.

## Browsers coming and going

`browser.created` and `browser.deleted` tell your backend when a browser starts and ends, whoever made or deleted it: your backend, a member in the console, or the deletion of a whole batch.

```json theme={null}
{ "id": "evt_9120", "object": "event", "type": "browser.deleted", "created": "…",
  "browser": { "id": "brw_k3m9x2p7qa4t", "object": "browser", "external_id": "user_829" },
  "data": { "text": "Browser deleted (deleted by its owner)", "external_id": "user_829", "why": "deleted by its owner" } }
```

* `browser.deleted` comes once the browser's profile and files are gone, which can be a few seconds after `DELETE` answered 202. It has the browser's id and `external_id`, so a receiver finds its own user, and nothing else of it: no name and no metadata, since the event outlives the browser. It stays in `GET /v1/events` for 24 hours, as long as a delivery waits, and goes at once when the workspace is deleted.
* `browser.created` has the browser's `metadata` too.
* Every event names its browser in `browser`, with its `external_id`, so a receiver finds its own user from any event alone.
* An endpoint filtered to one browser gets that browser's `browser.deleted` too, and goes a minute later.

## Check the signature

Every POST has these headers:

| Header | |
| - | - |
| `Hotkey-Signature` | `t=<unix seconds>,v1=<hex HMAC-SHA256>` |
| `Hotkey-Event-Id` | The event's id, `evt_…` |
| `Hotkey-Event-Type` | The event's type, such as `ask.done` |

The HMAC covers the string `<t>.<body>` under your secret. Compute it over the raw body, before any JSON parsing, and refuse a `t` older than a few minutes:

```js theme={null}
import crypto from 'node:crypto';

function verify(rawBody, header, secret, toleranceS = 300) {
  const m = /^t=(\d+),v1=([0-9a-f]{64})$/.exec(header ?? '');
  if (!m || Math.abs(Date.now() / 1000 - Number(m[1])) > toleranceS) return false;
  const want = crypto.createHmac('sha256', secret).update(`${m[1]}.${rawBody}`).digest('hex');
  return crypto.timingSafeEqual(Buffer.from(want), Buffer.from(m[2]));
}
```

## Delivery

* Answer with any 2xx status within 10 seconds.
* An endpoint gets its events one at a time, in order of their ids. The next goes as soon as the one before is answered, so answer first and do the work after: a receiver that takes 200 ms to answer gets at most 5 events a second, and the rest wait in line.
* Any other answer, or none, holds the endpoint: the same event is tried again after 30 s, 2 min, 10 min, 30 min, then every 2 h, and the events after it wait behind it. Once it gets a 2xx, the ones waiting go at once.
* An event that waits 24 hours without a 2xx is given up, and so is the oldest when 5,000 wait for one endpoint. The endpoint's `last_delivery.error` then says so.
* Deliveries that wait survive Hotkey's restarts and deploys: the next server sends them, in order. Only a crash of Hotkey's server can lose the ones of its last moment.
* An event can arrive twice, for example when a deploy cut a delivery off before its answer came. Use `Hotkey-Event-Id` to skip duplicates.
* Every event also stays in `GET /v1/events`. A receiver that keeps the last `evt_` id it saw can read anything it missed from there, with that id as `starting_after`.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.