AgentRail signs each webhook delivery with an HMAC signature. Before you process any payload, verify that signature against the raw request body and your webhook secret. The parse_webhook_event function handles verification and deserialization in one call.
Import
Verify and parse a delivery
parse_webhook_event raises an exception if the signature does not match or if the body cannot be deserialized.
Parameters
Use the raw request body
Pass the raw request body bytes or string to parse_webhook_event. Do not parse the body as JSON first. JSON re-serialization changes byte ordering and whitespace, which breaks the HMAC signature check.
In FastAPI, read the raw body with Request.body():
In Django or Flask, read request.body before any JSON parsing middleware runs.
Set the webhook secret
Your webhook secret (AGENTRAIL_WEBHOOK_SECRET) is separate from your API key. You set it when you create a webhook subscription — see POST /event-subscriptions for the secret parameter.