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

# Webhooks

> Get an HTTP request on your server when an upload is ready, a conversion finishes, an import completes or a plan limit is hit.

Much of what Dreep does finishes after your API call returns: a presigned upload lands, a video transform completes, a document conversion runs, an import works through a bucket. Instead of polling, add a webhook endpoint and Dreep sends a signed `POST` to your server when each of these happens.

> [!NOTE]
>
> Webhooks are on the **Starter** and **Pro** plans.

## Add an endpoint

1. In the dashboard, open **Developers** > **Webhooks**.
2. Click **Add endpoint**, enter your URL and pick the events you want.
3. Copy the signing secret. It starts with `whsec_` and is shown only once. Store it like any other secret, for example as `DREEP_WEBHOOK_SECRET`.

The URL must:

* use `https://`
* point at a public address (not `localhost`, a private IP range, or an internal hostname like `*.local` or `*.internal`)
* not contain a username or password
* be at most 2,048 characters

A project can have up to 10 endpoints. Each endpoint subscribes to its own set of events.

## Events

| Event | Sent when |
| :- | :- |
| `asset.ready` | An uploaded asset finished processing and can be served |
| `asset.failed` | An upload never arrived and was abandoned |
| `asset.deleted` | An asset was deleted |
| `conversion.completed` | A document conversion finished |
| `conversion.failed` | A document conversion failed for good |
| `video.variant.ready` | A video transform finished and replaced the upload |
| `video.variant.failed` | A video transform failed; the original upload was kept |
| `bg_remove.completed` | A background removal finished |
| `import.completed` | An import job finished |
| `import.failed` | An import job failed |
| `usage.limit_reached` | The project hit a plan limit |

`asset.*` events cover files you upload, whether directly, through a presigned upload or by import. Files Dreep creates for you, like a converted document or a background-removed image, send their own event (`conversion.completed`, `bg_remove.completed`) instead of `asset.ready`.

A video uploaded with a transform sends `asset.ready` once its final file is in place, together with `video.variant.ready`, or with `video.variant.failed` if the transform failed and the original was kept.

An import job is `import.failed` only when nothing in it imported. A partial import is `import.completed`, with the number that failed.

`usage.limit_reached` is sent at most once a day for each feature and limit, not on every blocked request.

There's also `webhook.test`, which only the **Send test event** button sends. You can't subscribe to it.

## Payload

Every delivery is a JSON object with the same envelope:

| Field | Type | Description |
| :- | :- | :- |
| `id` | string | The event id. The same on every retry and resend of this event. |
| `type` | string | The event type, for example `asset.ready`. |
| `createdAt` | string | When the event happened, ISO 8601 in UTC. |
| `projectId` | string | The project the event belongs to. |
| `data` | object | The event's details. Its shape depends on `type`, as shown below. |

Don't rely on the order of keys in the body.

### Asset events

`asset.ready`, `asset.failed`, `conversion.completed`, `video.variant.ready`, `video.variant.failed` and `bg_remove.completed` carry the asset:

```json theme={null}
{
  "id": "8b0e7c2a-5f1d-4c3b-9a6e-2d4f8b1c7e90",
  "type": "asset.ready",
  "createdAt": "2026-03-21T18:40:00.000Z",
  "projectId": "3c9d2e1f-7a6b-4c5d-8e9f-0a1b2c3d4e5f",
  "data": {
    "asset": {
      "id": "2f928a3f-1d2a-4a2b-9c3d-4e5f60718293",
      "type": "image",
      "folderId": null,
      "filename": "hero.jpg",
      "mimetype": "image/jpeg",
      "format": "jpg",
      "sizeBytes": 482113,
      "width": 1600,
      "height": 1067,
      "status": "ready",
      "url": "https://cdn.dreep.cloud/api/v1/fetch/2f928a3f-1d2a-4a2b-9c3d-4e5f60718293.jpg",
      "createdAt": "2026-03-21T18:39:58.000Z"
    }
  }
}
```

| Field | Description |
| :- | :- |
| `type` | `image` or `file`. |
| `folderId` | The folder the asset is in, or `null` at the root. |
| `format` | The image format. `null` for files. |
| `width` | `null` for files. Same for `height`. |
| `status` | `ready` for the success events. `abandoned` for `asset.failed` and `conversion.failed`. |
| `url` | Where the asset is served. Uses your custom domain when the project has one. |

`conversion.failed` adds an `error` next to the asset: `unconvertible`, `page_out_of_range` or `conversion_failed`.

```json theme={null}
{
  "id": "c41e6a0b-2d7f-4f3e-8b5a-91d0e2f3a4b6",
  "type": "conversion.failed",
  "createdAt": "2026-03-21T18:41:12.000Z",
  "projectId": "3c9d2e1f-7a6b-4c5d-8e9f-0a1b2c3d4e5f",
  "data": {
    "asset": {
      "id": "5a7c9e1b-3d4f-4a6b-8c0d-2e4f6a8b0c1d",
      "type": "file",
      "folderId": null,
      "filename": "contract.pdf",
      "mimetype": "application/pdf",
      "format": null,
      "sizeBytes": 0,
      "width": null,
      "height": null,
      "status": "abandoned",
      "url": "https://cdn.dreep.cloud/api/v1/fetch/5a7c9e1b-3d4f-4a6b-8c0d-2e4f6a8b0c1d",
      "createdAt": "2026-03-21T18:40:30.000Z"
    },
    "error": "unconvertible"
  }
}
```

### asset.deleted

The asset no longer exists, so only its id and type are sent:

```json theme={null}
{
  "id": "e7f1a2b3-c4d5-4e6f-8a9b-0c1d2e3f4a5b",
  "type": "asset.deleted",
  "createdAt": "2026-03-21T19:02:44.000Z",
  "projectId": "3c9d2e1f-7a6b-4c5d-8e9f-0a1b2c3d4e5f",
  "data": {
    "asset": {
      "id": "2f928a3f-1d2a-4a2b-9c3d-4e5f60718293",
      "type": "image"
    }
  }
}
```

### Import events

`import.completed` and `import.failed` carry the import job. `provider` is `cloudinary`, `s3` or `r2`.

```json theme={null}
{
  "id": "0d9c8b7a-6f5e-4d3c-2b1a-0f9e8d7c6b5a",
  "type": "import.completed",
  "createdAt": "2026-03-21T20:15:07.000Z",
  "projectId": "3c9d2e1f-7a6b-4c5d-8e9f-0a1b2c3d4e5f",
  "data": {
    "importJob": {
      "id": "6b5a4f3e-2d1c-4b0a-9f8e-7d6c5b4a3f2e",
      "provider": "s3",
      "status": "completed",
      "total": 1200,
      "succeeded": 1197,
      "failed": 3
    }
  }
}
```

### usage.limit\_reached

`featureKey` is the plan feature that ran out, such as `storage_bytes` or `transformations_monthly`. `limit` is the limit that was hit, including any add-ons, and `used` is the usage at that point.

```json theme={null}
{
  "id": "a1b2c3d4-e5f6-4a7b-8c9d-0e1f2a3b4c5d",
  "type": "usage.limit_reached",
  "createdAt": "2026-03-21T21:00:00.000Z",
  "projectId": "3c9d2e1f-7a6b-4c5d-8e9f-0a1b2c3d4e5f",
  "data": {
    "featureKey": "transformations_monthly",
    "limit": 100000,
    "used": 100000
  }
}
```

### webhook.test

```json theme={null}
{
  "id": "1d7f3a52-9c0e-4b8a-a6d1-5e2f7c9b0a34",
  "type": "webhook.test",
  "createdAt": "2026-03-21T18:40:00.000Z",
  "projectId": "3c9d2e1f-7a6b-4c5d-8e9f-0a1b2c3d4e5f",
  "data": {
    "message": "This is a test event from Dreep",
    "endpointId": "9a8b7c6d-5e4f-4a3b-2c1d-0e9f8a7b6c5d"
  }
}
```

## Headers

| Header | Value |
| :- | :- |
| `Content-Type` | `application/json` |
| `User-Agent` | `Dreep-Webhooks/1.0` |
| `Dreep-Signature` | `t=<unix seconds>,v1=<signature>`. See [Verify the signature](#verify-the-signature). |
| `Dreep-Event-Id` | The event id, the same as `id` in the body. |
| `Dreep-Event-Type` | The event type, the same as `type` in the body. |
| `Dreep-Delivery-Id` | This delivery. It stays the same across retries and changes on a resend. |

## Verify the signature

Anyone can send a request to your endpoint, so check every delivery's `Dreep-Signature` before acting on it. The header looks like this:

```text theme={null}
Dreep-Signature: t=1774118400,v1=4ad9aae4628f7c3dfb083d4afaaa7a69e8fd713b1ef5a09171338d3e597015ad
```

`t` is when the delivery was signed, in Unix seconds. `v1` is a hex HMAC-SHA256 of `` `${t}.${rawBody}` ``, keyed with your endpoint's full secret, `whsec_` included. Each retry is signed again with a fresh `t`.

> [!NOTE]
>
> Verify against the **raw** request body, byte for byte. If your framework has already parsed the JSON, re-serialising it won't give back the same bytes (key order, spacing and escaping can differ) and the signature won't match.

### With the Node SDK

`verifyWebhook` checks the signature and the timestamp and returns the parsed event. It throws `DreepWebhookSignatureError` if anything is wrong.

```typescript Express theme={null}
import express from "express";
import { DreepWebhookSignatureError, verifyWebhook } from "dreep";

const app = express();

// express.raw keeps req.body as a Buffer. Register this route before any
// app-wide express.json(), or exclude the path from it.
app.post("/webhooks/dreep", express.raw({ type: "application/json" }), (req, res) => {
  try {
    const event = verifyWebhook({
      payload: req.body,
      header: req.get("Dreep-Signature"),
      secret: process.env.DREEP_WEBHOOK_SECRET!,
    });

    res.sendStatus(200);
    queueEvent(event); // do the work after responding
  } catch (error) {
    if (error instanceof DreepWebhookSignatureError) {
      return res.status(400).send(error.message);
    }
    throw error;
  }
});
```

```typescript Next.js theme={null}
// app/webhooks/dreep/route.ts
import { DreepWebhookSignatureError, verifyWebhook } from "dreep";

export async function POST(request: Request) {
  const payload = await request.text();

  try {
    const event = verifyWebhook({
      payload,
      header: request.headers.get("Dreep-Signature"),
      secret: process.env.DREEP_WEBHOOK_SECRET!,
    });

    await queueEvent(event);
    return new Response(null, { status: 200 });
  } catch (error) {
    if (error instanceof DreepWebhookSignatureError) {
      return new Response(error.message, { status: 400 });
    }
    throw error;
  }
}
```

By default a delivery is rejected when `t` is more than 300 seconds from your server's clock, in either direction. Pass `toleranceSeconds` to change that.

### With Node's crypto module

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

const TOLERANCE_SECONDS = 300;

function verifyDreepSignature(rawBody: Buffer, header: string, secret: string): boolean {
  const parts = Object.fromEntries(
    header.split(",").map((part) => {
      const [key, ...rest] = part.trim().split("=");
      return [key, rest.join("=")];
    }),
  );
  const timestamp = Number(parts.t);
  const received = parts.v1;

  if (!Number.isInteger(timestamp) || !received) return false;
  if (Math.abs(Math.floor(Date.now() / 1000) - timestamp) > TOLERANCE_SECONDS) return false;

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

  const a = Buffer.from(expected);
  const b = Buffer.from(received);
  return a.length === b.length && timingSafeEqual(a, b);
}
```

### Other languages

1. Read the raw request body and the `Dreep-Signature` header.
2. Split the header on `,` and each part on the first `=` to get `t` and `v1`.
3. Compute HMAC-SHA256 over `{t}.{raw body}` with your full `whsec_` secret as the key, and hex-encode it.
4. Compare it with `v1` using a constant-time comparison, such as `hmac.compare_digest` in Python or `hmac.Equal` in Go.
5. Reject the request if `t` is more than 300 seconds from the current time.

## Respond quickly

Return any `2xx` status within 10 seconds. Anything else counts as a failed delivery and is retried:

* a non-`2xx` status, including redirects (`3xx` responses are not followed)
* no response within 10 seconds
* a connection error

Respond first and do slow work, like downloading the asset or updating other systems, in a background job. The first 1,024 characters of your response body are kept in the deliveries log, which helps when debugging.

## Retries and auto-disable

A failed delivery is tried up to 8 times in total. The waits between tries grow from 1 minute to about 12 hours (1m, 3m, 9m, 27m, 81m, about 4h, about 12h, each give or take 10%), so Dreep keeps trying for about 18 hours before giving up on a delivery.

If 10 deliveries in a row to the same endpoint use up all their tries, Dreep disables the endpoint and stops sending to it. Any successful delivery resets the count. Events that happen while an endpoint is disabled aren't sent to it and can't be resent later, and retries still queued for it are marked as failed.

To switch a disabled endpoint back on, fix the problem, use **Send test event** to check it, then enable it in **Developers** > **Webhooks**.

Deliveries can arrive out of order, and a retry can arrive after a later event. Use `createdAt` or fetch the current state from the API if order matters to you.

## Handle duplicates

The same event can reach you more than once, for example when your server handled it but the response timed out, or when someone resends it from the dashboard. The event id (`id` in the body and the `Dreep-Event-Id` header) never changes for an event, so use it to skip work you've already done:

```typescript theme={null}
const event = verifyWebhook({ payload, header, secret });

const isNew = await db.processedWebhookEvents.insertIfAbsent({ id: event.id });
if (!isNew) {
  return new Response(null, { status: 200 });
}

await queueEvent(event);
```

Return `2xx` for a duplicate too, or Dreep will keep retrying it.

## Test an endpoint

In **Developers** > **Webhooks**, open an endpoint and click **Send test event**. Dreep sends a `webhook.test` delivery straight away and shows your server's response. Test events are tried once, never retried, don't count towards auto-disable, and are sent even when the endpoint is disabled.

Each endpoint has a deliveries log with every attempt's status code, response body, error and duration. Deliveries are kept for 30 days. Click **Resend** on any delivery to send the same event again. A resend has the same event id and body and a new `Dreep-Delivery-Id`.

## Rotate the secret

If a secret leaks, open the endpoint and rotate it. The new secret is shown once. The old one stops working immediately, with no overlap period: every delivery from that point, including retries already queued, is signed with the new secret. Update the secret on your server straight after rotating, or deliveries will fail verification until you do. Failed deliveries can be resent from the log once your server has the new secret.


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