Webhooks
Set up and manage webhooks for real-time moderation events
Overview
Klyra webhooks allow your application to receive real-time notifications when moderation events occur. This enables you to build reactive systems that can immediately respond to moderation decisions without constantly polling the API.
Use Cases
- Receive notification when a batch moderation job completes
- Get alerted immediately when high-severity content is detected
- Trigger automated workflows based on moderation results
- Synchronize moderation decisions across multiple systems
- Log moderation activities for compliance purposes
Setting Up Webhooks
Step 1: Create a webhook endpoint
First, create an endpoint on your server that can receive POST requests from Klyra:
Step 2: Register the webhook in Klyra Dashboard
- Log in to the Klyra Dashboard
- Navigate to Project Settings > Webhooks
- Click Add Webhook Endpoint
- Enter the following details:
- Endpoint URL: The URL of your webhook endpoint (e.g.,
https://your-app.com/webhooks/klyra
) - Events to send: Select which events to receive
- Description: A friendly name for this webhook
- Endpoint URL: The URL of your webhook endpoint (e.g.,
- Click Generate Secret to create a signing secret
- Copy the generated secret and store it securely
- Click Create Webhook
Webhook Events
Klyra sends the following webhook events:
Event Type | Description |
---|---|
moderation.completed | A moderation request has been completed |
moderation.flagged | Content has been flagged as potentially violating |
moderation.batch.completed | A batch moderation job has finished |
moderation.appeal.received | A moderation decision appeal has been submitted |
moderation.appeal.resolved | A moderation appeal has been resolved |
Webhook Payload
All webhook payloads follow this format:
Example Payloads
Security
Verifying Signatures
To ensure webhooks are coming from Klyra and haven’t been tampered with, all webhook requests include a signature in the X-Klyra-Signature
header.
The signature is an HMAC SHA-256 hash created using your webhook secret and the request body:
Best Practices
- Store your webhook secret securely: Never expose your webhook secret in client-side code
- Always verify signatures: Reject requests with invalid signatures
- Implement idempotency: Webhook events may occasionally be delivered more than once
- Return 2xx responses quickly: Acknowledge webhook receipt promptly (within 10 seconds)
- Process webhooks asynchronously: Handle time-consuming tasks in background jobs
Retries and Failures
If your endpoint returns a non-2xx response or takes too long to respond, Klyra will retry the webhook with exponential backoff:
- 1st retry: 5 minutes after initial failure
- 2nd retry: 15 minutes after 1st retry
- 3rd retry: 60 minutes after 2nd retry
- 4th retry: 180 minutes after 3rd retry
- 5th retry: 360 minutes after 4th retry
After 5 failed attempts, the webhook delivery will be marked as failed and will not be retried again.
Webhook Logs
You can view webhook delivery history in the Klyra Dashboard:
- Go to Project Settings > Webhooks
- Select a webhook endpoint
- View the Delivery History tab
For each delivery attempt, you can see:
- Timestamp
- HTTP status code
- Response time
- Request/response bodies
- Error details (if any)
Testing Webhooks
You can send test webhook events from the Klyra Dashboard:
- Go to Project Settings > Webhooks
- Select a webhook endpoint
- Click Send Test Event
- Choose an event type and customize the payload if needed
- Click Send Test Event
For local development, we recommend using a service like ngrok to expose your local server to the internet.