Overview
Webhooks allow ElevenLabs to send real-time notifications to your application when certain events occur. This is useful for:- Receiving notifications when audio generation is complete
- Tracking usage and billing events
- Monitoring voice cloning progress
- Staying informed about account changes
Setting Up Webhooks
Configure Your Endpoint
First, create an endpoint in your application to receive webhook events:FastAPI Example
Webhook Signature Verification
The SDK provides theconstruct_event method to verify webhook signatures and prevent unauthorized requests.
How It Works
ElevenLabs signs each webhook with a secret key and includes:- A timestamp (
t=) to prevent replay attacks - A signature hash (
v0=) to verify authenticity
str
required
The raw webhook request body as a string. Do not parse it as JSON first.
str
required
The
elevenlabs-signature header from the webhook request.str
required
Your webhook secret from the ElevenLabs dashboard.
Verification Errors
Theconstruct_event method raises BadRequestError for the following issues:
Missing signature header
Missing signature header
The
elevenlabs-signature header was not included in the request.Webhook secret not configured
Webhook secret not configured
No secret was provided to the verification function.
Invalid signature format
Invalid signature format
The signature header doesn’t contain the expected
t= and v0= components.Timestamp outside tolerance
Timestamp outside tolerance
The webhook timestamp is older than 30 minutes, indicating a potential replay attack.
Signature mismatch
Signature mismatch
The computed signature doesn’t match the provided signature.
Security Best Practices
Always verify signatures
Never process webhook events without verifying the signature first.
Use HTTPS
Only accept webhooks over HTTPS to prevent man-in-the-middle attacks.
Keep secrets secure
Store webhook secrets in environment variables, not in code.
Handle replay attacks
The 30-minute timestamp tolerance helps prevent replay attacks.
Processing Webhook Events
Once verified, process the webhook payload based on the event type:Async Webhook Handling
The async client also supports webhook verification:The
construct_event method is synchronous even when using AsyncElevenLabs because it only performs local computation (HMAC verification). No API calls are made.Complete Example
Here’s a complete webhook handler with proper error handling:Testing Webhooks
During development, use tools like ngrok to expose your local server:Webhook Response Guidelines
Return 200 for successful processing
Return 200 for successful processing
Always return a 200 status code when the webhook is processed successfully, even if your business logic encounters non-critical errors.
Return 400 for invalid signatures
Return 400 for invalid signatures
Return 400 when signature verification fails to indicate a client error.
Handle retries gracefully
Handle retries gracefully
ElevenLabs will retry failed webhooks. Make your endpoint idempotent to handle duplicate events.
Respond quickly
Respond quickly
Process webhooks asynchronously if needed. Respond within 30 seconds to avoid timeouts.
Troubleshooting
Signature Verification Fails
- Ensure you’re passing the raw request body, not parsed JSON
- Check that your webhook secret matches the one in your dashboard
- Verify the signature header is being read correctly
- Check server time synchronization (timestamp tolerance is 30 minutes)
Missing Signature Header
Testing Signature Verification
Next Steps
Error Handling
Learn about webhook-specific error handling
Async Client
Use webhooks with async frameworks