Webhooks
Instead of polling the API to check request status, you can provide acallback_url when creating a request. HITL.sh will send an HTTP POST to your callback URL when the request is completed, timed out, or cancelled.
How Callback URLs Work
When creating a request, include thecallback_url parameter:
Webhook Payload
When a request is completed, HITL.sh sends a POST request to yourcallback_url with the following JSON payload:
Payload Fields
Event type - always
"request.completed", "request.timeout", or "request.cancelled"Unique identifier for the request
ID of the loop that processed this request
Final status:
"completed", "timeout", or "cancelled"The actual response from the reviewer (format varies by response_type). Null if timed out or cancelled.
Information about the reviewer who responded. Null if timed out or cancelled.
ISO 8601 timestamp when the response was submitted. Null if timed out or cancelled.
Time taken from creation to response in seconds. Null if timed out or cancelled.
ISO 8601 timestamp when the request was created
Event Types
request.completed
request.completed
Sent when a reviewer successfully completes the request.
request.timeout
request.timeout
Sent when no reviewer responds within the timeout period.Your application should use the
default_response value you specified when creating the request.request.cancelled
request.cancelled
Sent when the request is cancelled via the API before completion.
Implementing a Webhook Endpoint
Basic Endpoint
Best Practices
1. Return 200 OK Quickly
Always return a200 OK response immediately after receiving the webhook. Process the payload asynchronously to avoid timeouts:
2. Handle Retries Gracefully
HITL.sh will retry failed webhook deliveries up to 3 times with exponential backoff. Make your endpoint idempotent to handle duplicate deliveries:3. Validate Webhook Authenticity
While HITL.sh callback URLs are set per-request and only known to you, you should still validate incoming webhooks:4. Use HTTPS
Always use HTTPS endpoints for yourcallback_url to ensure webhook payloads are encrypted in transit:
5. Handle Errors Gracefully
If your webhook endpoint fails, HITL.sh will retry. Log errors for debugging:Testing Webhooks
Local Development with ngrok
Use ngrok to expose your local server for webhook testing:Manual Testing
Create a test request with your callback URL:Troubleshooting
Webhook Not Received
Webhook Not Received
Possible causes:
- Callback URL is not publicly accessible
- Using HTTP instead of HTTPS
- Firewall blocking incoming requests
- Webhook endpoint returned error status
- Test your endpoint with curl or Postman
- Ensure HTTPS is used
- Check firewall rules
- Return 200 OK status code
Duplicate Webhooks
Duplicate Webhooks
Cause: Webhook delivery retries after temporary failuresSolution: Implement idempotency by tracking processed request IDs
Webhook Timeout
Webhook Timeout
Cause: Your endpoint takes too long to respondSolution: Return 200 OK immediately and process payload asynchronously
Next Steps
Create Request API
Learn how to create requests with callback URLs
Request Monitoring
Understand request lifecycle and polling alternatives
Integration Examples
See complete examples with webhook integration
Error Handling
Handle webhook delivery failures and retries