# Signed webhooks

> Pass a `webhook_url` when you create a video and, when the job ends, we POST the same JSON `GET /api/v1/videos/:id` returns to that URL, once, signed with your account’s secret. Check the `Webhook-Signature` header before you trust it, and poll if a callback never arrives.

Muse Video is a video model made by Meta. Muse-Video.dev is an independent API, not affiliated with or endorsed by Meta; the Muse Video name is a trademark of its owner.

## When we send it

When a video job ends (success, failure or cancellation) we send one POST to its `webhook_url`. The URL must be https and may not point at a private network. Each video gets one attempt with a 10-second timeout and no automatic retry, so polling `GET /api/v1/videos/:id` is the dependable fallback.

## What arrives

```http
POST /hooks/muse-video HTTP/1.1
Content-Type: application/json
User-Agent: Muse-Video.dev-Webhooks/1
Webhook-Signature: t=1764321164,v1=5d2c8f…e41a

{
  "type": "video.succeeded",
  "data": {
    "id": "3f9c2b7e-5a1d-4c8e-9b0f-2d6e8a41c7d3",
    "status": "success",
    "model": "muse-video",
    "resolution": "720p",
    "seconds": 5,
    "credits": 15,
    "creditsHeld": 0,
    "creditsCharged": 15,
    "outputs": ["https://cdn.muse-video.dev/…/video.mp4"],
    …
  }
}
```

- `type`: `video.succeeded` (delivered and charged) or `video.failed` (failed or canceled; the held credits were released).
- `data`: exactly the video object `GET /api/v1/videos/:id` returns.

## The signature

`Webhook-Signature: t=<unix seconds>,v1=<hex signature>`, where the signature is HMAC-SHA256 with your `whsec_` secret over the string `t + "." + raw body`. To check it:

1. Read the raw body, before any JSON parsing.
2. Reject a `t` more than 5 minutes from your clock, which stops replays.
3. Compare your signature with `v1` in constant time.

The secret is on [Settings → API keys](https://muse-video.dev/settings/apikeys): one per account, shared by all its keys. Store it as an environment variable such as `MUSE_VIDEO_WEBHOOK_SECRET`.

## Node.js (Express)

```js
import crypto from 'node:crypto';
import express from 'express';

const app = express();
const SECRET = process.env.MUSE_VIDEO_WEBHOOK_SECRET; // whsec_…

// Keep the raw body: the signature covers the exact bytes we sent.
app.post('/hooks/muse-video', express.raw({ type: 'application/json' }), (req, res) => {
  const header = req.get('Webhook-Signature') ?? '';
  const match = /^t=(\d+),v1=([0-9a-f]{64})$/.exec(header);
  if (!match) return res.status(400).end();
  const [, t, v1] = match;
  if (Math.abs(Date.now() / 1000 - Number(t)) > 300) return res.status(400).end();

  const expected = crypto
    .createHmac('sha256', SECRET)
    .update(`${t}.${req.body.toString('utf8')}`)
    .digest('hex');
  if (!crypto.timingSafeEqual(Buffer.from(expected), Buffer.from(v1)))
    return res.status(400).end();

  const event = JSON.parse(req.body.toString('utf8'));
  // event.type: "video.succeeded" | "video.failed"; event.data: the video
  res.status(200).end();
});
```

## Python (Flask)

```python
import hashlib, hmac, os, re, time
from flask import Flask, request, abort

app = Flask(__name__)
SECRET = os.environ["MUSE_VIDEO_WEBHOOK_SECRET"].encode()  # whsec_…

@app.post("/hooks/muse-video")
def muse_video_hook():
    header = request.headers.get("Webhook-Signature", "")
    m = re.fullmatch(r"t=(\d+),v1=([0-9a-f]{64})", header)
    if not m or abs(time.time() - int(m[1])) > 300:
        abort(400)
    body = request.get_data()  # raw bytes, before any JSON parsing
    expected = hmac.new(SECRET, m[1].encode() + b"." + body, hashlib.sha256).hexdigest()
    if not hmac.compare_digest(expected, m[2]):
        abort(400)
    event = request.get_json()
    # event["type"]: "video.succeeded" | "video.failed"
    return "", 200
```

## Handling callbacks reliably

- **Answer first, work later:** return 2xx at once and put the download and database work on a queue.
- **De-duplicate by id:** a callback and your own poll can both see the result; key your work on `data.id`.
- **Poll as a fallback:** if no callback has come a few minutes after you expect one, call `GET /api/v1/videos/:id`.
- **Keep the file:** download `outputs[0]` to your own storage once you have it.

## FAQ

### Do you retry failed webhooks?

No. Each video gets one attempt with a 10-second timeout. If it never arrives, poll GET /api/v1/videos/:id.

### Where is the signing secret?

On Settings → API keys. It starts with whsec_ and there is one per account.

### Do failed jobs send a webhook too?

Yes, as video.failed, by which time the held credits have been released.

### Can the webhook URL be plain http?

No. webhook_url must be https and may not point at a private network address.


---

Source: https://muse-video.dev/webhooks · Site index for AI agents: https://muse-video.dev/llms.txt · Full content: https://muse-video.dev/llms-full.txt
