Endpoint
Authentication
Webhook requests are verified using the OpenAI SDK’s webhook verification system with HMAC signature validation.Configuration
Set your webhook secret in environment variables:Verification Process
The webhook endpoint verifies each incoming request:- Extracts the raw request body and headers
- Uses OpenAI SDK’s
client.webhooks.unwrap()method - Validates the signature using your webhook secret
- Returns
401 Unauthorizedif verification fails
Event Types
The webhook handles three event types:| Event Type | Description |
|---|---|
realtime.call.incoming | Triggered when a new call arrives |
realtime.call.ended | Triggered when a call ends normally |
realtime.call.hangup | Triggered when a call is hung up |
realtime.call.hungup | Alternative hangup event |
Webhook Processing
1. Webhook Verification
All requests must pass signature verification using your webhook secret.2. Deduplication
The system maintains a cache of seen webhook IDs to prevent duplicate processing:- Webhook IDs are stored for 30 minutes
- Cache is cleaned up every 30 minutes
- Duplicate webhooks return
200 OKwith{"ok": true, "deduped": true}
3. Event Routing
After verification and deduplication, events are routed to appropriate handlers based on event type.Response Format
All webhook responses return200 OK with a JSON body:
Indicates whether the webhook was processed successfully
Present for
realtime.call.incoming events. true if the call was acceptedPresent when a call is rejected. Possible values:
capacity- System at capacitytenant_resolve_failed- Could not identify tenanttenant_not_configured- Tenant not set upinstructions_missing- No instructions configuredtenant_config_parse_error- Invalid tenant configuration
true if this webhook was already processedtrue if the webhook was ignoredReason for ignoring the webhook:
missing_webhook_idmissing_call_idunsupported_event_type
The resolved tenant ID (for accepted calls)
true if fallback instructions were used due to database errorError message if processing failed
Error Handling
Verification Failures
Invalid signatures return401 Unauthorized:
Invalid Requests
Malformed webhooks return400 Bad Request:
Graceful Degradation
The system handles various error conditions:- Database errors: Falls back to baseline instructions to keep service available
- Missing call IDs: Returns success but ignores the webhook
- Unknown event types: Returns success but logs warning
Security Best Practices
- Keep secrets secure: Store
OPENAI_WEBHOOK_SECRETin environment variables, never in code - Validate all webhooks: The system automatically verifies all incoming requests
- Monitor for duplicates: Built-in deduplication prevents replay attacks
- Use HTTPS: Always expose your webhook endpoint over HTTPS in production
Testing Webhooks
Test your webhook endpoint:Webhook signatures must be generated using your webhook secret. Use the OpenAI SDK’s signing utilities for testing.
Next Steps
Incoming Calls
Handle incoming call events with capacity gating
Call Events
Process call ended and hangup events