Webhooks
Webhooks notify your application when events occur in AgentGate. Instead of polling for status, receive push notifications when runs complete.Why Use Webhooks
Setting Up Webhooks
Create a Webhook
Endpoint Requirements
Your webhook endpoint must:- Use HTTPS (HTTP not allowed)
- Be publicly accessible
- Respond within 30 seconds
- Return a 2xx status code for success
Event Types
Run Events
Verification Events
Common Subscriptions
Payload Format
All webhooks follow this structure:run.completed Payload
run.failed Payload
Signature Verification
Always verify webhook signatures to ensure authenticity.Signature Header
Webhooks include anX-AgentGate-Signature header:
Verification Process
1
Get Raw Body
Access the raw request body before JSON parsing.
2
Compute HMAC
Calculate HMAC-SHA256 of the body using your webhook secret.
3
Compare Signatures
Use constant-time comparison to match computed vs received signature.
Verification Code
Handling Webhooks
Best Practices
Respond Quickly
Respond Quickly
Return 200 immediately, then process asynchronously:
Implement Idempotency
Implement Idempotency
Handle duplicate deliveries gracefully using the event ID:
Use a Queue
Use a Queue
For reliability, queue webhooks for processing:
Retry Behavior
If your endpoint fails, AgentGate retries:
After 5 failed attempts, the delivery is abandoned.
What Triggers Retries
- HTTP 4xx responses (except 410)
- HTTP 5xx responses
- Connection timeouts
- Connection refused
Avoiding Retries
- Return 200/201/204 promptly
- Return 410 if you want to stop retries
- Ensure endpoint is accessible
Testing Webhooks
Test Endpoint
Send a test event to verify configuration:Local Development
Use tunneling for local testing:- Start a tunnel (ngrok, localtunnel, etc.)
- Create a webhook with your tunnel URL
- Submit a work order
- Receive webhook on localhost
Managing Webhooks
List Webhooks
Update Webhook
Delete Webhook
Related
Tenant Context
Include tenant info in webhook payloads
API Reference
Webhooks API endpoints