# Webhooks

> Register an https URL and receive a signed POST when a job's status changes (finished, failed, cancelled, waiting for review). Signatures follow the Standard Webhooks spec. Answer `2xx` quickly; failed deliveries are retried for about 3 days.

## At a glance

- Manage endpoints: `POST /api/v1/webhook-endpoints` (API key with `write`, or the website Profile → API access)
- Limit: 5 endpoints per account
- Target: public `https://` URL (no private or local addresses, no user:password)
- Delivery: `POST`, `Content-Type: application/json`, 10 s timeout, redirects are not followed
- Headers: `webhook-id`, `webhook-timestamp`, `webhook-signature` (Standard Webhooks v1, HMAC-SHA256)
- Latency: usually within 15–30 s of the status change
- Guarantee: at least once. The same event can arrive more than once — deduplicate on `webhook-id`.
- Order: not guaranteed. Use `data.status` and `data.updatedAt`, or GET the job.

## Event types

`<object>.<status>`:

| Object | Events | Poll URL in `data.links.self` |
|---|---|---|
| `translation` | `translation.analyzed`, `translation.images_waiting`, `translation.completed`, `translation.completed_partial`, `translation.failed`, `translation.cancelled` | `/api/v1/translate/status/{jobId}` |
| `video` | `video.awaiting_review`, `video.completed`, `video.failed`, `video.cancelled` | `/api/v1/video/jobs/{id}` |
| `meeting` | `meeting.completed`, `meeting.failed`, `meeting.cancelled` (`meeting.awaiting_review` is no longer sent: meetings are approved automatically) | `/api/v1/meetings/jobs/{id}` |
| `meeting` (results, early access) | `meeting.minutes_revised`, `meeting.minutes_regenerated`, `meeting.document_ready`, `meeting.mindmap_ready` on a finished meeting (`data.status` is the part after the dot; see [Meetings: early-access features](https://faraatarjomeh.com/api/v1/docs/guides/meeting-extras.md#result-webhooks)) | `/api/v1/meetings/jobs/{id}` |
| `audio` | `audio.awaiting_review`, `audio.completed`, `audio.failed`, `audio.cancelled` | `/api/v1/audio/jobs/{id}` |
| `farsi_tts` | `farsi_tts.awaiting_review`, `farsi_tts.completed`, `farsi_tts.failed`, `farsi_tts.cancelled` | `/api/v1/farsi-tts/jobs/{id}` |
| `transcription` | `transcription.completed`, `transcription.failed`, `transcription.cancelled` | `/api/v1/transcription/jobs/{id}` |
| `content` | `content.completed`, `content.completed_partial`, `content.failed` | `/api/v1/content/jobs/{id}` |
| `account` | `account.balance_low` (early access: only when a low-balance threshold is set, see [Meetings: early-access features](https://faraatarjomeh.com/api/v1/docs/guides/meeting-extras.md#account-events-and-limits)) | `/api/v1/account` |
| (test) | `webhook.test` | — |

The live list: `GET /api/v1/webhook-endpoints/event-types`. Events are sent for every job of the account (created by API or on the website) whose status changed after the endpoint was created.

## Payload

```json
{
  "type": "translation.completed",
  "timestamp": "2026-09-25T10:40:02.511Z",
  "id": "evt_4f0c2d9a7b1e3c5d6e7f8a9b0c1d2e3f",
  "data": {
    "object": "translation",
    "id": "3f1c2b7e-9a4d-4c1e-8f7a-2b9c4d5e6f70",
    "status": "completed",
    "createdAt": "2026-09-25T10:11:40.000Z",
    "updatedAt": "2026-09-25T10:39:58.000Z",
    "links": {
      "self": "https://faraatarjomeh.com/api/v1/translate/status/3f1c2b7e-9a4d-4c1e-8f7a-2b9c4d5e6f70"
    }
  }
}
```

| Field | Type | Notes |
|---|---|---|
| `type` | string | event type |
| `timestamp` | string | when the event was made (ISO 8601) |
| `id` | string | event id; equals the `webhook-id` header; the same on every retry |
| `data.object` | string | `translation`, `video`, `meeting`, `audio`, `farsi_tts`, `transcription`, `content`, `webhook_endpoint` (test) |
| `data.id` | string | job id |
| `data.status` | string | the job's status when the event was made |
| `data.links.self` | string | GET this with your API key for the full job (for translations: status and outputs) |
| `data.errorCode` | string | translation only, on `failed`, when known (e.g. `INSUFFICIENT_CREDITS`); same as `customerErrorCode` |
| `data.customerErrorCode` | string | every job kind, on `failed`, when known |
| `data.externalId`, `data.metadata` | string, object | early access: as sent when the job was created |
| `data.balance`, `data.threshold`, `data.currency` | number, number, string | `account.balance_low` only (`data.object` is `account`, `data.id` the account id) |

The payload is small on purpose. GET `data.links.self` for details and downloads.

## Create an endpoint

```http
POST /api/v1/webhook-endpoints HTTP/1.1
Authorization: Bearer fara_sk_...
Content-Type: application/json

{"url": "https://example.com/fara/webhook", "events": ["translation.completed", "translation.failed"], "description": "production"}
```

```json
{
  "id": "66f1c3aa4b5c6d7e8f901234",
  "url": "https://example.com/fara/webhook",
  "description": "production",
  "events": ["translation.completed", "translation.failed"],
  "enabled": true,
  "disabledReason": null,
  "createdAt": "2026-09-25T10:00:00.000Z",
  "updatedAt": "2026-09-25T10:00:00.000Z",
  "lastSuccessAt": null,
  "lastFailureAt": null,
  "secret": "whsec_MfKQ9r8GKYqrTwjUPD8ILPZIo2LaLaSw"
}
```

| Field | Type | Required | Default | Notes |
|---|---|---|---|---|
| `url` | string | yes | — | public `https://` URL, max 2048 characters |
| `events` | string[] | no | `["*"]` | event types, or `["*"]` for all |
| `description` | string | no | `""` | max 200 characters |

`secret` is returned **only here** and by `POST /api/v1/webhook-endpoints/{id}/rotate-secret`. Store it; you need it to verify signatures.

Other calls: `GET /api/v1/webhook-endpoints`, `GET /api/v1/webhook-endpoints/{id}`, `PATCH /api/v1/webhook-endpoints/{id}` (`url`, `events`, `description`, `enabled`), `DELETE /api/v1/webhook-endpoints/{id}` (204).

## Verify the signature

Headers on every delivery:

```http
webhook-id: evt_4f0c2d9a7b1e3c5d6e7f8a9b0c1d2e3f
webhook-timestamp: 1727260802
webhook-signature: v1,<base64 signature>
```

Algorithm (Standard Webhooks v1):

1. `signedContent = webhook-id + "." + webhook-timestamp + "." + rawBody` — the raw request body bytes, **before** any JSON parsing.
2. `key = base64decode(secret without the "whsec_" prefix)`
3. `expected = "v1," + base64(HMAC_SHA256(key, signedContent))`
4. `webhook-signature` is a space-separated list; accept if **any** entry equals `expected` (constant-time compare).
5. Reject if `webhook-timestamp` is more than 5 minutes from your clock (replay protection).

### Test vector

Use it to check your verifier (set your clock check to accept timestamp `1727260802`):

| Input | Value |
|---|---|
| secret | `whsec_MfKQ9r8GKYqrTwjUPD8ILPZIo2LaLaSw` |
| `webhook-id` | `evt_test_4f0c2d9a7b1e3c5d6e7f8a9b` |
| `webhook-timestamp` | `1727260802` |
| raw body | `{"type":"webhook.test","timestamp":"2026-09-25T10:40:02.511Z","id":"evt_test_4f0c2d9a7b1e3c5d6e7f8a9b","data":{"object":"webhook_endpoint","id":"66f1c3aa4b5c6d7e8f901234"}}` |
| expected `webhook-signature` | `v1,GFlDRlD6Muw+Px5RJ0u9M+wOYWBDAjxOXh31j/USX5k=` |

Any Standard Webhooks library also works (`standardwebhooks` for JavaScript, Python, PHP, Go …).

```js
// Node.js (Express). Use the RAW body: express.raw, not express.json.
import crypto from "node:crypto";
import express from "express";

const SECRET = process.env.FARA_WEBHOOK_SECRET; // "whsec_..."

function verify(rawBody, headers) {
  const id = headers["webhook-id"];
  const ts = headers["webhook-timestamp"];
  const sigs = String(headers["webhook-signature"] || "").split(" ");
  if (!id || !ts || Math.abs(Date.now() / 1000 - Number(ts)) > 300) return false;
  const key = Buffer.from(SECRET.replace(/^whsec_/, ""), "base64");
  const expected = "v1," + crypto.createHmac("sha256", key)
    .update(`${id}.${ts}.${rawBody}`).digest("base64");
  return sigs.some((s) => s.length === expected.length &&
    crypto.timingSafeEqual(Buffer.from(s), Buffer.from(expected)));
}

const app = express();
app.post("/fara/webhook", express.raw({ type: "application/json" }), (req, res) => {
  if (!verify(req.body.toString("utf8"), req.headers)) return res.sendStatus(400);
  const event = JSON.parse(req.body);
  // Deduplicate on event.id, then queue your work and answer fast.
  res.sendStatus(204);
});
app.listen(3000);
```

```python
# Python (Flask)
import base64, hashlib, hmac, os, time
from flask import Flask, request

SECRET = os.environ["FARA_WEBHOOK_SECRET"]  # "whsec_..."
app = Flask(__name__)

def verify(raw_body: bytes, headers) -> bool:
    msg_id = headers.get("webhook-id")
    ts = headers.get("webhook-timestamp")
    sigs = headers.get("webhook-signature", "").split(" ")
    if not msg_id or not ts or abs(time.time() - int(ts)) > 300:
        return False
    key = base64.b64decode(SECRET.removeprefix("whsec_"))
    signed = f"{msg_id}.{ts}.".encode() + raw_body
    expected = "v1," + base64.b64encode(hmac.new(key, signed, hashlib.sha256).digest()).decode()
    return any(hmac.compare_digest(s, expected) for s in sigs)

@app.post("/fara/webhook")
def webhook():
    raw = request.get_data()  # raw bytes, before JSON parsing
    if not verify(raw, request.headers):
        return "", 400
    event = request.get_json()
    # Deduplicate on event["id"], then queue your work and answer fast.
    return "", 204
```

```php
<?php
// PHP
$secret = getenv('FARA_WEBHOOK_SECRET'); // "whsec_..."
$raw = file_get_contents('php://input');
$id = $_SERVER['HTTP_WEBHOOK_ID'] ?? '';
$ts = $_SERVER['HTTP_WEBHOOK_TIMESTAMP'] ?? '';
$sigs = explode(' ', $_SERVER['HTTP_WEBHOOK_SIGNATURE'] ?? '');

$ok = false;
if ($id !== '' && ctype_digit($ts) && abs(time() - (int)$ts) <= 300) {
    $key = base64_decode(preg_replace('/^whsec_/', '', $secret));
    $expected = 'v1,' . base64_encode(hash_hmac('sha256', "$id.$ts.$raw", $key, true));
    foreach ($sigs as $s) {
        if (hash_equals($expected, $s)) { $ok = true; break; }
    }
}
if (!$ok) { http_response_code(400); exit; }
$event = json_decode($raw, true);
// Deduplicate on $event['id'], then queue your work and answer fast.
http_response_code(204);
```

## Your response

| You answer | We do |
|---|---|
| `2xx` within 10 s | delivered |
| `410 Gone` | stop: the endpoint is switched off (`disabledReason: "endpoint_gone"`) |
| anything else, timeout, or connection error | retry |

Answer first, work later: put the event on your own queue and return `2xx` at once.

## Retries

A failed delivery is tried again after 5 s, 5 min, 30 min, 2 h, 5 h, 10 h, 14 h, 20 h and 24 h (10 tries, about 3 days). Each try has a new `webhook-timestamp` and signature; `webhook-id` stays the same. An endpoint where every delivery has failed for 5 days is switched off (`disabledReason: "failing_for_days"`). Turn it back on with `PATCH /api/v1/webhook-endpoints/{id}` and `{"enabled": true}`.

## Test and inspect

- `POST /api/v1/webhook-endpoints/{id}/test` sends a `webhook.test` event at once and returns `{"deliveryId", "eventId", "delivered", "responseStatus", "error"}`. Test events are tried once.
- `GET /api/v1/webhook-endpoints/{id}/deliveries` lists deliveries, newest first (cursor paging; kept 30 days): `status` is `pending`, `succeeded` or `failed`, with `attempts`, `nextAttemptAt`, `lastResponseStatus`, `lastError`.
- `POST /api/v1/webhook-endpoints/{id}/deliveries/{deliveryId}/retry` puts a failed delivery back in the queue (`202`).

## Errors and recovery

| HTTP | code | When | What to do |
|---|---|---|---|
| 400 | `INVALID_WEBHOOK_URL` | not https, bad URL, credentials in it | fix the URL |
| 400 | `WEBHOOK_HOST_UNRESOLVED` | host name does not resolve | fix DNS or the URL |
| 400 | `WEBHOOK_HOST_NOT_PUBLIC` | host resolves to a private/local address | use a public host |
| 400 | `INVALID_EVENTS` | unknown event type or empty list | use `GET /api/v1/webhook-endpoints/event-types` |
| 409 | `WEBHOOK_ENDPOINT_LIMIT_REACHED` | 5 endpoints already | delete one |
| 404 | `FEATURE_DISABLED` | webhooks switched off right now | poll instead; retry later |

## Rules for agents

- Verify every signature; drop unsigned or stale requests.
- Deduplicate on `webhook-id`; process each event once.
- Treat a webhook as a hint: GET `data.links.self` before acting on money or files.
- If you cannot receive webhooks, poll (see [Conventions](https://faraatarjomeh.com/api/v1/docs/conventions.md#asynchronous-jobs)).
