Overview
Webhooks enable your application to receive real-time notifications when tasks complete. Instead of polling for results, configure a webhook endpoint to receive data automatically when the AI agent finishes its work.
Use cases:
- Automated data pipelines that trigger on task completion
- Real-time notifications to downstream systems
- Integration with third-party services and APIs
- Event-driven architectures without polling overhead
Configuration
Add a webhook object to your session or task request to enable webhook notifications.
Webhook Parameters
submittedData Options
Basic Example
With Structured Output
Combine webhooks with structured output for validated JSON delivered directly to your endpoint.
Use submittedData: "ai_response" to receive only the AI’s output (text, structured_json, or structured_csv), reducing payload size and simplifying your webhook handler.
Webhook Payload
The payload sent to your endpoint depends on the submittedData setting.
full_response Payload
ai_response Payload
just_ping Payload
Receiving Webhooks
Your webhook endpoint should:
- Accept POST requests with JSON body
- Return a 2xx status code to acknowledge receipt
- Process the webhook asynchronously if needed
Example Webhook Handler (Node.js/Express)
Example Webhook Handler (Python/Flask)
Security Best Practices
1. Use HTTPS
Always use HTTPS endpoints for webhooks to encrypt data in transit.
2. Verify Authorization
Include an auth token and verify it in your webhook handler.
3. Validate Payload Structure
Validate incoming data matches your expected schema before processing.
4. Use Unique Tokens Per Webhook
Generate unique tokens for different webhook endpoints to limit exposure if one is compromised.
Error Handling
If your webhook endpoint fails to respond or returns an error, the webhook delivery will not be retried. Ensure your endpoint is reliable and returns quickly.
Webhook deliveries are not retried on failure. Design your endpoint to be highly available and respond within 30 seconds.
Recommended Approach
- Acknowledge receipt immediately with a 200 status
- Process the data asynchronously
- Implement your own retry logic if needed
Use Cases
Data Pipeline Automation
Automatically ingest extracted data into your database or data warehouse.
Notification Systems
Trigger alerts or notifications when tasks complete.
Third-Party Integrations
Send data directly to external services like Zapier, Make, or n8n.