Webhooks
Webhooks send events to your own URL as they happen: a budget running out, a provider failing, an MCP server going down, a key created or revoked. Use them for a chat channel, a pager, a ticket or a SIEM. Deliveries are signed per the Standard Webhooks specification, so any of its libraries can verify them.
webhooks: ops-alerts: url: https://hooks.example.com/promptgate secret: ${PROMPTGATE_WEBHOOK_SECRET} # whsec_… or 24+ bytes events: [budget.*, provider.failing, mcp.server_down] siem: url: https://siem.internal.example/ingest secret: ${SIEM_WEBHOOK_SECRET} events: ["*"] headers: { Authorization: "Bearer ${SIEM_TOKEN}" } private: true # the receiver is on a private network| field | default | |
|---|---|---|
url |
— | absolute http or https URL; no credentials in it (use headers) |
secret |
— | signing secret: whsec_ followed by base64 (as Standard Webhooks libraries generate it), or any string of at least 24 bytes. openssl rand -base64 32 makes one. Never logged or shown. |
events |
— | event types, prefixes such as budget.*, or *; see promptgate events. A pattern that matches no event is refused at load. |
headers |
— | sent with every delivery, e.g. the receiver’s own token; values may use ${ENV}. Never logged or shown. |
timeout |
10s |
for one attempt, 1s to 1m |
private |
false |
allow a receiver on a private, loopback or link-local address |
disabled |
false |
keep the entry but queue nothing for it |
Names are lowercase letters, digits and -. Changes apply on reload,
without a restart.
What a receiver gets
Section titled “What a receiver gets”Every delivery is a POST with the event as its JSON body (see
payload) and these headers:
| header | |
|---|---|
webhook-id |
the event’s id (evt_…); the same on every retry, so a receiver can drop duplicates |
webhook-timestamp |
Unix seconds when this attempt was signed |
webhook-signature |
v1, and base64 of HMAC-SHA256 over <id>.<timestamp>.<body> |
content-type |
application/json |
user-agent |
PromptGate-Webhooks/<version> |
A 2xx answer counts as delivered. Anything else, a timeout or a
connection error is a failure.
Verifying the signature
Section titled “Verifying the signature”Check the signature over the raw body, before you parse it, and reject timestamps more than five minutes away from your clock, so a recorded delivery can’t be replayed later. Compare in constant time.
With a Standard Webhooks library (JavaScript, Python, Go, Ruby, PHP, Java, C#, Rust, Elixir):
from standardwebhooks.webhooks import Webhook
wh = Webhook(secret) # the same whsec_… stringevent = wh.verify(raw_body, headers) # raises on a bad signature or an old timestampThe libraries expect a whsec_ secret. With a plain secret, give them
whsec_ followed by the base64 of it.
Without a library, in Python:
import base64, hashlib, hmac, time
def verify(secret: str, headers, body: bytes) -> bool: key = base64.b64decode(secret[6:]) if secret.startswith("whsec_") else secret.encode() msg_id, ts = headers["webhook-id"], headers["webhook-timestamp"] if abs(time.time() - int(ts)) > 300: return False mac = hmac.new(key, f"{msg_id}.{ts}.".encode() + body, hashlib.sha256).digest() expected = "v1," + base64.b64encode(mac).decode() return any(hmac.compare_digest(expected, s) for s in headers["webhook-signature"].split())In Node.js:
import { createHmac, timingSafeEqual } from "node:crypto";
function verify(secret, headers, rawBody) { const key = secret.startsWith("whsec_") ? Buffer.from(secret.slice(6), "base64") : Buffer.from(secret); const id = headers["webhook-id"], ts = headers["webhook-timestamp"]; if (Math.abs(Date.now() / 1000 - Number(ts)) > 300) return false; const mac = createHmac("sha256", key).update(`${id}.${ts}.`).update(rawBody).digest("base64"); const expected = Buffer.from(`v1,${mac}`); return headers["webhook-signature"].split(" ").some( (s) => s.length === expected.length && timingSafeEqual(Buffer.from(s), expected));}In Go, with the standard library only:
func verify(secret string, h http.Header, body []byte) bool { key := []byte(secret) if s, ok := strings.CutPrefix(secret, "whsec_"); ok { key, _ = base64.StdEncoding.DecodeString(s) } id, ts := h.Get("webhook-id"), h.Get("webhook-timestamp") sec, err := strconv.ParseInt(ts, 10, 64) if err != nil || time.Since(time.Unix(sec, 0)).Abs() > 5*time.Minute { return false } mac := hmac.New(sha256.New, key) fmt.Fprintf(mac, "%s.%s.", id, ts) mac.Write(body) want := []byte("v1," + base64.StdEncoding.EncodeToString(mac.Sum(nil))) for _, sig := range strings.Fields(h.Get("webhook-signature")) { if hmac.Equal([]byte(sig), want) { return true } } return false}The signature header may hold several signatures separated by spaces (the specification allows that during a secret rotation); accept the delivery when one of them matches.
Delivery
Section titled “Delivery”- Durable. Every event a webhook wants is written to a queue in the
request log before it is sent, so deliveries survive a restart. The
gateway (
promptgate start) sends them. Withlogging.store: offthere is no queue and no webhooks. - In order, per webhook. A webhook gets its next event only after the one before was delivered or given up. One slow receiver doesn’t hold up the others.
- Retries. After a failure the next attempt follows after 30 s, 2 min, 10 min, 30 min, 1 h, 3 h, 6 h, 12 h and 24 h, each ±10 %. After 10 attempts, about two days, the delivery is given up. A receiver that is offline for a day still gets every event once it is back.
- At least once. A receiver may see an event twice, for example when
its
2xxwas lost on the way back. Drop duplicates bywebhook-id. 410 Gonegives the delivery up at once.- Redirects are not followed. A
3xxis a failure; pointurlat the final address. - SSRF check. Like the API Gateway,
deliveries are refused for private, loopback and link-local addresses
at connection time, unless the webhook has
private: trueor the address is insecurity.ssrf.allow. - Limits. At most 10,000 deliveries wait per webhook. Beyond that, new events for it are dropped and the gateway logs a warning, so a receiver that is gone for long can’t fill the disk. Finished deliveries are kept for 30 days, with the status and the first 2 KB of the receiver’s answer. Deliveries of a webhook that is removed or disabled are given up within the hour.
Events from every process reach the webhooks: a promptgate keys create on the command line is written to the audit trail,
and the running gateway picks it up within a second and delivers it.
Inspecting and testing
Section titled “Inspecting and testing”promptgate webhooks list # state, waiting, delivered and given up in 24 hpromptgate webhooks test ops-alerts # send a signed webhook.test now, show the answerpromptgate webhooks deliveries ops-alerts --state failedpromptgate webhooks deliveries --id 1842 # the event and the receiver's answerpromptgate webhooks redeliver --failed ops-alerts # or: redeliver 1842 1843listshows a webhook as failing while its oldest waiting delivery has failed attempts — with when it was queued and the last error — and as idle before its first delivery.testsends awebhook.testevent directly, signed and with the webhook’s headers, timeout and SSRF check, whatever events the webhook takes. It doesn’t enter the queue; exit code 1 unless the receiver answers2xx. Use it after changing a URL, secret or header.redeliverputs finished deliveries back into the queue with their attempts reset: by id, or every delivery a webhook gave up. They go out before the webhook’s newer events; the running gateway picks them up within seconds. Each call is recorded in the audit trail aswebhook.redelivered.- The same in the web UI (Observability →
Webhooks), in the Management API
(
/control/v1/webhooks,webhook-deliveries,webhook-test,webhook-redeliver) and as MCP control tools. - Metrics:
promptgate_webhook_deliveries_total{webhook,result}andpromptgate_webhook_pending{webhook}— alert on a queue that keeps growing.
A receiver on your own machine needs private: true:
webhooks: local: url: http://127.0.0.1:9000/hook secret: test-secret-of-at-least-24-bytes events: ["*"] private: truepromptgate keys create test then sends a key.created event.