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

# Webhook Delivery and Retries

> How HeyGen sends a webhook: the request and its x-heygen-event-id, x-heygen-delivery-id and signature headers, the 5-second timeout, which answers are retried within about 35 seconds, and how to deduplicate.

![](https://mintcdn.com/heygen-1fa696a7/-JfaMNWMFzwSpwo3/docs/images/theme/research-2.webp?fit=max\&auto=format\&n=-JfaMNWMFzwSpwo3\&q=85\&s=27bce1b17a9aacf4af71d4702eb3f524)

This page describes what HeyGen sends to your server for each [webhook event](https://developers.heygen.com/docs/webhook-events.md), what your server should answer, and what happens when it does not. The same rules apply to [registered endpoints](https://developers.heygen.com/docs/webhooks.md#create-an-endpoint) and to a per-request `callback_url`.

## Where an event is sent

When a job reaches a state that has an event, such as a video finishing, HeyGen sends the event to every **target** it has:

* each enabled endpoint in your workspace that subscribes to that `event_type` (an endpoint with `events: null` subscribes to all of them);
* the `callback_url` that the request which created the job set, if it set one.

Each target gets its own **delivery**, sent in parallel and retried on its own. A delivery is one or more HTTP **attempts**. Only endpoints whose `status` is `enabled` receive events.

## The request

Each attempt is a `POST` to the target URL. The body is a compact JSON object with two fields:

```json theme={null}
{"event_type":"avatar_video.success","event_data":{"video_id":"8d3c2f0a1b4e4c6d9e7f0a1b2c3d4e5f","url":"https://...","callback_id":"order-1042"}}
```

`event_data` depends on the event type; see [Webhook Events](https://developers.heygen.com/docs/webhook-events.md#event-data-payloads).

| Header | Value |
| - | - |
| `x-heygen-event-id` | The event's ID. It is the same on every attempt, on every target, and on every [Send again](https://developers.heygen.com/docs/webhook-send-again.md) of the event. Deduplicate on it. |
| `x-heygen-delivery-id` | The ID of this delivery: new for each target and for each Send again, and shared by that delivery's retries. |
| `x-heygen-delivery-attempt` | The attempt number within the delivery, starting at `1`. |
| `signature` | Hex HMAC-SHA256 of the raw body with the endpoint's signing secret. Sent to registered endpoints only; see [Verifying Payloads](https://developers.heygen.com/docs/webhooks.md#verifying-payloads). |
| `Content-Type` | `application/json` |

The event ID is in the headers only, not in the body. The same ID is the `event_id` in [`GET /v3/webhooks/events`](https://developers.heygen.com/docs/reference/list-webhook-events) and [`GET /v3/webhooks/deliveries`](https://developers.heygen.com/docs/reference/list-webhook-deliveries), so you can look up any request your server received.

> [!WARNING]
>
> Deliveries to a `callback_url` are **not signed**: there is no `signature` header. Put a long random token in the callback URL's path, check the `callback_id` you set, and treat the body as a hint: fetch the job from the API before you act on it. To receive signed events, [register an endpoint](https://developers.heygen.com/docs/webhooks.md#create-an-endpoint).

## What your server should answer

Answer with any `2xx` status within **5 seconds**. Do the real work after you answer: store the event, put it on a queue, answer `200`, and process it from the queue. A handler that renders, transcodes, or calls other services before it answers will time out, and the attempt is retried.

How each answer is treated:

| Your server's answer | Result |
| - | - |
| `2xx` | Succeeded. No more attempts. |
| `5xx`, `429` or `408` | Failed. Retried. |
| No answer within 5 seconds (`timeout`) or a refused or reset connection (`connection`) | Failed. Retried. |
| Any other `4xx`, such as `400`, `401`, `403` or `404` | Failed at once. Not retried. |
| `3xx` redirect | Failed at once (`redirect_refused`). Redirects are never followed, so the signed body never goes to a host you did not register. |
| The URL is not a public HTTPS address (`non_public`) | Failed at once. Nothing is sent. |

Answer `4xx` only when the request itself is wrong, such as a bad signature. If your server is overloaded or a dependency is down, answer `503` or `429` so the attempt is retried.

## Retry timing

* A delivery makes **at most 5 attempts**.
* The wait between attempts is about 2, 4, 8 and 8 seconds, each varied by up to 25%.
* A `Retry-After` header in seconds on a retried answer, such as a `429` or `503`, sets the shortest wait before the next attempt. A `Retry-After` longer than the time left ends the delivery as failed. A `Retry-After` given as a date is ignored.
* All of an event's deliveries share one **35-second** limit, counted from the first attempt. When the next attempt cannot start within it, the delivery ends as failed.

There is no later retry schedule. If your server is unreachable for longer than about 35 seconds, the events in that window are not delivered. Find them in [`GET /v3/webhooks/events`](https://developers.heygen.com/docs/webhook-deliveries#find-events-that-did-not-arrive) and [send them again](https://developers.heygen.com/docs/webhook-send-again.md), or fetch the jobs' state from the API.

## URL requirements

A target URL must:

* use `https`, on port 443, 8443, 8080, 8000 or 80;
* have a host name that resolves only to public IPv4 addresses. A receiver reachable only over IPv6 is not reached;
* carry no user name or password (`https://user:pass@...`);
* answer directly, without a redirect.

A URL that breaks one of these rules fails with `error_class` `non_public` or `redirect_refused`, which are not retried.

## Deduplicate and order

Delivery is **at least once**. Your server can receive the same event more than once when:

* your server processed an attempt but its answer was lost or late, so the attempt was retried;
* the event was [sent again](https://developers.heygen.com/docs/webhook-send-again.md);
* the event has two targets that reach the same system, such as an endpoint and a `callback_url`.

Record each `x-heygen-event-id` you have processed, and skip one you have already seen. Keep the IDs for at least 30 days, the period in which an event can be sent again.

```javascript Node.js theme={null}
app.post("/webhooks/heygen", async (req, res) => {
  // Verify the signature first: see /docs/webhooks#verifying-payloads.
  const eventId = req.header("x-heygen-event-id");

  // INSERT ... ON CONFLICT DO NOTHING returns false when the ID was already stored.
  const isNew = await db.recordEventId(eventId);
  if (isNew) {
    await queue.enqueue(JSON.parse(req.body.toString("utf8")));
  }
  res.sendStatus(200); // answer 200 for duplicates too, so they are not retried
});
```

```python Python (Flask) theme={null}
@app.post("/webhooks/heygen")
def heygen_webhook():
    # Verify the signature first: see /docs/webhooks#verifying-payloads.
    event_id = request.headers["x-heygen-event-id"]

    # INSERT ... ON CONFLICT DO NOTHING returns False when the ID was already stored.
    if db.record_event_id(event_id):
        queue.enqueue(request.get_json())
    return "", 200  # answer 200 for duplicates too, so they are not retried
```

Events are not guaranteed to arrive in the order they happened: a retried event can arrive after a later one. When order matters, fetch the job's current state from the API instead of applying events in the order they arrive.

## Media URLs in events

Download URLs in `event_data`, such as `url` on `avatar_video.success`, are pre-signed and expire. Download the file soon after the event arrives, or fetch a fresh URL from the job's get endpoint; see [Webhook Events](https://developers.heygen.com/docs/webhook-events.md#other-event-types). [`GET /v3/webhooks/events`](https://developers.heygen.com/docs/reference/list-webhook-events) and [Send again](https://developers.heygen.com/docs/webhook-send-again.md) sign these URLs again, so they return working links.

## Next steps

> [card] [Monitor deliveries](https://developers.heygen.com/docs/webhook-deliveries.md)
>
> See each attempt's status code, error and latency, and find events that never arrived.

> [card] [Send events again](https://developers.heygen.com/docs/webhook-send-again.md)
>
> Resend an event from the last 30 days to an endpoint or callback URL.


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