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

# Webhooks

> Get notified when a generation ends: endpoints, payloads, signatures and retries.

Argil sends an HTTP `POST` to your URL when an event happens. Webhooks follow the [Standard Webhooks](https://www.standardwebhooks.com) specification, so existing libraries verify them.

## Two ways to subscribe

| | Webhook endpoint | Per request |
| - | - | - |
| How | `POST /v2/webhook_endpoints` once | `"webhook_url"` on `POST /v2/generations` |
| Receives | Every subscribed event of the workspace | That generation’s final event |
| Signed | Yes, one secret per endpoint | No |
| Good for | Backends | Scripts, n8n, Make, Zapier |

Both can be used together: an event goes to every matching destination. A per-request delivery carries no `webhook-signature`: treat it as a notification, and read the generation with `GET /v2/generations/{id}` before acting on it.

Endpoints belong to the workspace: any of its API keys manages them, and they also receive the V1 events they subscribe to (in the V1 format).

## Events

| Type | When |
| - | - |
| `generation.succeeded` | Outputs are stored and visible in your library. |
| `generation.failed` | The generation failed; `error` says why; `cost` says what was refunded. |
| `session.idle` | An [agent session](https://docs.argil.ai/v2/agent/sessions.md) started through the API or MCP handed the turn back; the session, with its `stop_reason` and `questions`. |
| `output.created` | Such a session published a result; the artifact. |

Only final events are sent, so each generation produces exactly one, and order does not matter. More event types will be added (assets, apps, agent runs); ignore types you do not handle. Subscribe with `"enabled_events": ["*"]` to receive future types too, V1 events included.

## Payload

The body is an event wrapping the **full generation**, so you rarely need a follow-up `GET`:

```http theme={null}
POST /argil HTTP/1.1
Content-Type: application/json
webhook-id: evt_5c7e9a1b3d5f4a7c9e1b3d5f7a9c1e48
webhook-timestamp: 1793786643
webhook-signature: v1,K5oZfzN95Z9UVu1EsfQmfVNQhnkZ2pj9o9NDN/H/pI4=
```

```json theme={null}
{
  "id": "evt_5c7e9a1b3d5f4a7c9e1b3d5f7a9c1e48",
  "object": "event",
  "type": "generation.succeeded",
  "created_at": "2026-11-03T10:01:12.000Z",
  "data": {
    "object": {
      "id": "gen_6f1c2a9e4b7d4c1e9a3f0b5d8e2c7a14",
      "object": "generation",
      "status": "succeeded",
      "outputs": [{ "type": "video", "asset": { "id": "asset_e8b1…", "url": "https://argildotai.s3-accelerate.amazonaws.com/…" } }],
      "cost": { "currency": "credit", "estimated": 55.92, "reserved": 56, "charged": 56, "refunded": 0 },
      "metadata": { "order_id": "A-1042" }
    }
  }
}
```

## Verify signatures

Always verify before trusting a payload. The signature is an HMAC-SHA256, with your secret, of `{webhook-id}.{webhook-timestamp}.{raw body}`. Reject timestamps more than 5 minutes old to block replays.

```ts TypeScript theme={null}
import { Webhook } from "standardwebhooks";

const wh = new Webhook(process.env.ARGIL_WEBHOOK_SECRET!); // "whsec_..."

export async function POST(req: Request) {
  const body = await req.text(); // the raw body, before any JSON parsing
  let event;
  try {
    event = wh.verify(body, Object.fromEntries(req.headers));
  } catch {
    return new Response("invalid signature", { status: 400 });
  }
  await queue.push(event); // acknowledge fast, process asynchronously
  return new Response(null, { status: 204 });
}
```

```python Python theme={null}
from standardwebhooks.webhooks import Webhook

wh = Webhook(os.environ["ARGIL_WEBHOOK_SECRET"])

@app.post("/argil")
def argil_webhook(request):
    try:
        event = wh.verify(request.body, request.headers)
    except Exception:
        return Response(status=400)
    queue.push(event)
    return Response(status=204)
```

```ts Manual (Node) theme={null}
import { createHmac, timingSafeEqual } from "node:crypto";

function verify(secret: string, id: string, timestamp: string, body: string, header: string) {
  if (Math.abs(Date.now() / 1000 - Number(timestamp)) > 300) return false;
  const key = Buffer.from(secret.replace(/^whsec_/, ""), "base64");
  const expected = createHmac("sha256", key).update(`${id}.${timestamp}.${body}`).digest();
  return header.split(" ").some((part) => {
    const [version, sig] = part.split(",");
    const given = Buffer.from(sig ?? "", "base64");
    return version === "v1" && given.length === expected.length && timingSafeEqual(given, expected);
  });
}
```

## Respond fast, process later

* Answer any `2xx` within **10 seconds**. Do the work in a queue.
* Deduplicate on `webhook-id`: it is the event id and stays the same across retries.
* Redirects are not followed. Return `410 Gone` to disable the endpoint.

## Retries

A delivery that times out or gets a non-2xx response is retried after 30 seconds, 2 minutes, 10 minutes, 1 hour, 6 hours, then every 12 hours (with jitter), for **3 days**. After 3 days of failures, the endpoint is disabled (`status: "disabled"`, `disabled_reason: "failing"`) and the workspace owner is emailed. Re-enable it with `PATCH /v2/webhook_endpoints/{id}` and `"status": "enabled"`; what it missed is not replayed.

Webhooks are at least once and can be late. For anything that must not be missed, also reconcile periodically with `GET /v2/generations?completed_after=…`: it lists the generations created through the API whose final event was sent since that time. Ask from a minute before your last reconciliation, and skip the ids you already handled: an event can be stamped a moment before it becomes visible.

## Network

Your URL must be public HTTPS: hosts that resolve to a private network are refused.


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