Skip to main content

Webhooks

Instead of polling the API to check request status, you can provide a callback_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 the callback_url parameter:

Webhook Payload

When a request is completed, HITL.sh sends a POST request to your callback_url with the following JSON payload:

Payload Fields

event
string
Event type - always "request.completed", "request.timeout", or "request.cancelled"
request_id
string
Unique identifier for the request
loop_id
string
ID of the loop that processed this request
status
string
Final status: "completed", "timeout", or "cancelled"
response_data
object
The actual response from the reviewer (format varies by response_type). Null if timed out or cancelled.
response_by
object
Information about the reviewer who responded. Null if timed out or cancelled.
response_at
string
ISO 8601 timestamp when the response was submitted. Null if timed out or cancelled.
response_time_seconds
number
Time taken from creation to response in seconds. Null if timed out or cancelled.
created_at
string
ISO 8601 timestamp when the request was created

Event Types

Sent when a reviewer successfully completes the request.
Sent when no reviewer responds within the timeout period.
Your application should use the default_response value you specified when creating the request.
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 a 200 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 your callback_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

Possible causes:
  • Callback URL is not publicly accessible
  • Using HTTP instead of HTTPS
  • Firewall blocking incoming requests
  • Webhook endpoint returned error status
Solutions:
  • Test your endpoint with curl or Postman
  • Ensure HTTPS is used
  • Check firewall rules
  • Return 200 OK status code
Cause: Webhook delivery retries after temporary failuresSolution: Implement idempotency by tracking processed request IDs
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