Is there any API so that I can add or remove webho...
# ask-ai
f
Is there any API so that I can add or remove webhooks for the self-hosted LiveKit?
t
Thanks for reaching out, Punit. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
You can add webhooks for individual egress jobs, but you cannot add or remove project‑wide webhooks via an API on self‑hosted LiveKit. • Per‑egress webhooks: include a
webhooks
array in Egress API requests (e.g.,
StartRoomCompositeEgress
,
StartTrackEgress
,
StartWebEgress
) with
url
and optional
signing_key
to receive lifecycle events for that job. • Project‑wide webhooks: must be set in
livekit.yaml
under the
webhook
section (
api_key
,
urls
)—these are changed in the config file and not via an API. • SDKs: server SDKs can help verify webhook payloads but don’t provide an API to modify global webhook URLs. If you need dynamic management of global webhook endpoints, a recommended pattern is to point LiveKit’s static webhook URL at a proxy service you control that forwards events to endpoints stored in your database. Would you like an example of how to include
webhooks
in an egress request or a sketch of the proxy pattern? Sources: Webhooks | LiveKit docs | Egress API | LiveKit docs
f
If you need dynamic management of global webhook endpoints, a recommended pattern is to point LiveKit’s static webhook URL at a proxy service you control that forwards events to endpoints stored in your database. Would you like an example of how to include
webhooks
in an egress request or a sketch of the proxy pattern?
t
Which example would you like to see: • 1) a sample Egress request showing the
webhooks
field, • 2) a sketch of the proxy‑service pattern for dynamic project‑wide webhooks, or • 3) both?
f
2
t
You're asking for a sketch of the proxy-service pattern to manage global webhook endpoints dynamically. Below is a concise design and implementation outline you can adapt. Design overview • LiveKit → sends events to a single static webhook URL (configured in livekit.yaml). • Proxy service → receives LiveKit events, verifies signature if used, looks up registered target endpoints from a datastore, and forwards events to those endpoints (optionally signing/transforming). • Admin API/UI → lets you add/remove target endpoints stored in the datastore without changing LiveKit config. • Datastore → stores webhook targets with metadata (url, enabled, event filters, signing key, retry policy). • Worker/Queue → handles delivery retries, backoff, and failures asynchronously. Minimal data model (example) • id • url • enabled (bool) • events (list of event types to receive, or null for all) • signing_key (optional, used to sign forwarded requests) • retry_policy (max_retries, backoff) • last_status, last_error, created_at, updated_at Proxy behavior (request flow) 1. Receive request from LiveKit at /livekit/webhook. 2. Verify signature (if LiveKit signs events) using configured verification key. 3. Parse event type and payload. 4. Query datastore for enabled targets matching the event type. 5. Enqueue delivery tasks for each target (push job into queue). 6. Respond 200 to LiveKit quickly to avoid timeouts. Delivery worker behavior 1. Pop delivery job (contains target, payload, headers). 2. Optionally sign or add identifying headers (e.g., X-Forwarded-From, X-Signature). 3. POST to target.url with payload and headers. 4. On failure, record error, update last_status, and retry per retry_policy using backoff. 5. If permanently failed, mark disabled or alert admins. Security and reliability notes • Verify LiveKit signatures to avoid spoofing. • Rate-limit outgoing deliveries and queue large fan-outs. • Use idempotency keys or retries with deduplication to avoid duplicate processing. • Encrypt signing keys at rest; restrict access to datastore. • Expose metrics and logs for delivery success/failure rates. • Consider webhook batching or sampling if fan‑out is very large. Simple implementation sketch (endpoints) • POST /livekit/webhook — receives LiveKit events. • POST /admin/webhooks — add webhook target. • GET /admin/webhooks — list targets. • PATCH /admin/webhooks/{id} — update enable/disable, filters. • DELETE /admin/webhooks/{id} — remove target. Example delivery task payload (worker) { "target_id": "abc", "url": "https://example.com/hook", "payload": { "event": "...", "data": {...} }, "headers": { "X-Forwarded-From": "livekit-proxy" }, "attempt": 0 } Operational recommendations • Start with synchronous forwarding and limited concurrency for small scale; move to queued workers as scale grows. • Implement exponential backoff with jitter for retries. • Provide a dashboard showing delivery history and failures for each target. • Optionally allow per-target event filters to reduce unnecessary deliveries. Would you like a small code example in Node.js or Go for the proxy receiver + worker enqueue?