# Webhooks

> Get notified when research, provider reports and merges finish, and verify that events come from Deeper Research.

Source: https://deeperesearch.com/docs/api/webhooks/

Webhooks tell your server when something finishes, so you don’t have to poll.

## Events

| Event                      | Sent when                                                |
| -------------------------- | -------------------------------------------------------- |
| `research.completed`       | Research finished with at least one report               |
| `research.failed`          | Research finished without any report                     |
| `research.cancelled`       | Research was cancelled                                   |
| `research.run.completed`   | One provider’s report is ready (one event per provider)  |
| `research.merge.completed` | A synthesis merge finished; `report_id` is the synthesis |
| `research.merge.failed`    | A synthesis merge failed                                 |

The exact payload of each event is in the [API reference](https://deeperesearch.com/docs/api/reference/).

## Adding an endpoint

```bash
curl https://deeperesearch.com/v1/webhooks \
  -H "Authorization: Bearer $DEEPER_RESEARCH_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "url": "https://example.com/hooks/deeper", "events": ["research.completed", "research.failed"] }'
```

Leave out `events` to receive all of them. The URL must be public and use `https`.

Caution

The response includes the endpoint’s signing `secret` (`whsec_…`). It’s shown only once, so store it now.

## What you receive

Each event is a `POST` with a JSON body:

```json
{
  "id": "research.completed:6f0c2a1e-…",
  "type": "research.completed",
  "created_at": "2026-11-19T14:02:11.482Z",
  "data": {
    "research": {
      "id": "6f0c2a1e-…",
      "status": "completed",
      "query": "Which Postgres-backed job queues…",
      "charged_usd": 3.42,
      "runs": [{ "vendor": "parallel", "offering": "pro-fast", "state": "completed", "charged_usd": 1.2 }]
    }
  }
}
```

Answer with any `2xx` status within 10 seconds. Do slow work, like fetching the reports, after you’ve answered.

## Verifying signatures

Events are signed following the [Standard Webhooks](https://www.standardwebhooks.com/) spec, so any Standard Webhooks library can verify them. Each request has three headers:

| Header              | Contents                                         |
| ------------------- | ------------------------------------------------ |
| `webhook-id`        | The event id                                     |
| `webhook-timestamp` | When it was sent, in Unix seconds                |
| `webhook-signature` | `v1,` followed by a base64 HMAC-SHA256 signature |

The signature is computed over `{webhook-id}.{webhook-timestamp}.{raw body}`, with your secret (without its `whsec_` prefix, base64-decoded) as the key. Verify it against the **raw** request body, before parsing the JSON, and reject events more than five minutes old.

- JavaScript

  ```js
  import crypto from "node:crypto";


  export function verifyWebhook(rawBody, headers, secret) {
    const id = headers["webhook-id"];
    const timestamp = headers["webhook-timestamp"];
    const signatures = headers["webhook-signature"] ?? "";
    if (!id || !timestamp || Math.abs(Date.now() / 1000 - Number(timestamp)) > 300) return false;


    const key = Buffer.from(secret.replace(/^whsec_/, ""), "base64");
    const expected = crypto.createHmac("sha256", key).update(`${id}.${timestamp}.${rawBody}`).digest();
    return signatures.split(" ").some((entry) => {
      const [version, signature] = entry.split(",");
      const given = Buffer.from(signature ?? "", "base64");
      return version === "v1" && given.length === expected.length && crypto.timingSafeEqual(given, expected);
    });
  }
  ```

- Python

  ```python
  import base64, hashlib, hmac, time


  def verify_webhook(raw_body: bytes, headers, secret: str) -> bool:
      msg_id = headers.get("webhook-id")
      timestamp = headers.get("webhook-timestamp")
      signatures = headers.get("webhook-signature", "")
      if not msg_id or not timestamp or abs(time.time() - int(timestamp)) > 300:
          return False


      key = base64.b64decode(secret.removeprefix("whsec_"))
      signed = f"{msg_id}.{timestamp}.".encode() + raw_body
      expected = base64.b64encode(hmac.new(key, signed, hashlib.sha256).digest()).decode()
      return any(
          version == "v1" and hmac.compare_digest(signature, expected)
          for version, _, signature in (entry.partition(",") for entry in signatures.split())
      )
  ```

## Retries and duplicates

If your endpoint doesn’t answer `2xx` in time, the event is retried with increasing delays, up to 8 more times over several hours, then marked failed. [`GET /v1/webhooks/{id}/deliveries`](https://deeperesearch.com/docs/api/reference/operations/listwebhookdeliveries/) shows each delivery’s attempts, last response status and last error.

The same event can arrive more than once, and events can arrive out of order. Use the event `id` to ignore events you’ve already handled.

## Removing an endpoint

[`DELETE /v1/webhooks/{id}`](https://deeperesearch.com/docs/api/reference/operations/deletewebhook/) stops all deliveries to it.
