---
title: "Replay events"
description: "Send a range of EventWolf's event history to an endpoint again, after previewing the matches and deliveries with a dry run."
url: "https://agentpost.tools/docs/eventwolf/guides/replays"
kind: guide
needs:
  - what: "The `api` helper"
    from: "https://agentpost.tools/docs/platform/quickstart.md"
  - what: "A `dev` secret key, `key`, for a project that adopted EventWolf"
    from: "https://agentpost.tools/docs/platform/guides/keys.md"
  - what: "An endpoint with a subscription, `endpoint`"
    from: "https://agentpost.tools/docs/eventwolf/guides/webhooks.md"
---

# Replay events

Use this guide to send events again that a receiver never got or lost: events accepted before its subscription existed or while it was paused, or a range a receiver must rebuild from. A replay makes new deliveries, so a delivery that failed is better [retried](/docs/eventwolf/guides/failed-deliveries.md). [Replays](/docs/eventwolf/concepts/replays.md) explains what a replay sends and how a receiver tells it apart.

## Before you start

-   The `api` helper, from [Platform quickstart](/docs/platform/quickstart.md).
-   A `dev` secret key, `key`, for a project that adopted EventWolf, from [Create a project and issue a key](/docs/platform/guides/keys.md).
-   An endpoint with a subscription, `endpoint`, from [Receive webhooks](/docs/eventwolf/guides/webhooks.md).

This page's code continues the script of the pages above: run its blocks after theirs, in the same file. To run them as a script of their own, first copy each helper from the page that defines it, and set each other value, such as a key or an ID, to one you already have.

## 1\. Preview the replay

To replay a paused window, set `from` and `to` to the start and end of the pause. Set `target.subscriptionId` to replay one webhook subscription or `target.endpointId` to replay the endpoint’s subscriptions. Choose `definitions: 'historical'` to use the webhook filter and target in force when each event arrived. Choose `definitions: 'current'` to apply the filters and targets you have now.

Name the events by a [filter](/docs/eventwolf/concepts/filters.md) and a receipt-time range. Name the target, a webhook subscription or an endpoint, and the [definitions](/docs/eventwolf/concepts/replays.md#current-or-historical-definitions) to use. This example uses `current` to match against the endpoint’s non-deleted subscriptions, including paused ones. Send it with `dryRun: true` first to get a `preview` without creating a replay.

```ts
const replayRequest = {
  filter: { types: ['request.resolved'] },
  from: new Date(Date.now() - 60 * 60 * 1000).toISOString(),
  to: new Date().toISOString(),
  target: { endpointId: endpoint.id },
  definitions: 'current',
};
const { preview } = await api('POST', '/v1/events/replays', key, {
  ...replayRequest,
  dryRun: true,
});
console.log(preview.counts); // { scanned: 2, matched: 2, deliveries: 2 }
```

`scanned` counts the events in the range that meet the filter. `matched` counts event and subscription pairs. `deliveries` counts the delivery records the replay would create, including any that would be skipped. Check the counts before step 2. A preview that reaches its scan limit sets `partial: true`.

## 2\. Run the replay

A replay sends real webhooks, and what it sends can’t be taken back. Run it with the same request, without `dryRun`:

```ts
const { replay } = await api('POST', '/v1/events/replays', key, replayRequest);
console.log(replay.id.slice(0, 4)); // rpl_
```

It runs in the background. [Cancel it](/docs/eventwolf/reference/replays.md#cancel-a-replay) to stop it between batches. Deliveries already queued continue normally.

## Check it worked

Read the replay until it finishes:

```ts
let finished = replay;
for (let wait = 0; wait < 30 && finished.status === 'running'; wait += 1) {
  await new Promise((resolve) => setTimeout(resolve, 1000));
  ({ replay: finished } = await api(
    'GET',
    `/v1/events/replays/${replay.id}`,
    key,
  ));
}
console.log(finished.status, finished.counts.deliveries); // completed 2
```

A completed replay has finished creating its deliveries. [List deliveries](/docs/eventwolf/reference/deliveries.md#list-deliveries) shows their status alongside the endpoint’s other deliveries. Replay deliveries start with a new `webhook-id` and `x-eventwolf-trigger: replay`. The event carries its original `source` and `id` for deduplication.
