The Open Chat Widget uses two separate API keys to secure different endpoint categories.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/farrugiag/open-chat-widget/llms.txt
Use this file to discover all available pages before exploring further.
API Key Types
WIDGET_API_KEY
Protects all chat endpoints that the widget and headless clients use:POST /v1/chat- Non-streaming chatPOST /v1/chat/stream- Streaming chat (NDJSON)POST /chat- Legacy streaming endpoint
ADMIN_API_KEY
Protects admin endpoints for viewing conversations:GET /v1/admin/conversations- List conversationsGET /v1/admin/conversations/:conversationId- Get conversation thread
ADMIN_API_KEY is optional. If not configured, admin endpoints return 503 Service Unavailable.Timing-Safe Comparison
All API key validation uses thesecureEquals function to prevent timing attacks:
- Converts both strings to buffers
- Checks length equality first (fast path for obvious mismatches)
- Uses Node.js
crypto.timingSafeEqual()for constant-time comparison - Prevents attackers from measuring response times to guess key characters
Authentication Flow
Chat Endpoints
TherequireChatApiKey middleware validates chat requests:
X-Api-Key or X-Widget-Api-Key headers for backward compatibility.
Admin Endpoints
TherequireAdminApiKey middleware validates admin requests:
API Key Rotation
Follow these steps to rotate API keys without downtime:Rotating WIDGET_API_KEY
- Generate new key: Create a strong random string (32+ characters)
-
Update backend environment: Set new
WIDGET_API_KEYand redeploy -
Update widget embedding: Change
data-api-keyattribute on all embedded widgets
-
Update headless clients: Update
X-Api-Keyheader in all API calls - Verify: Test chat functionality with new key
Rotating ADMIN_API_KEY
- Generate new key: Create a strong random string
-
Update backend environment: Set new
ADMIN_API_KEYand redeploy -
Update dashboard environment: Set new
ADMIN_API_KEYin dashboard config if applicable -
Update admin clients: Update
X-Admin-Api-Keyheader in any admin API integrations - Verify: Test admin endpoints with new key
Best Practices
- Generate strong keys: Use cryptographically secure random generators (32+ characters)
- Rotate regularly: Change keys quarterly or after suspected exposure
- Separate keys: Keep
WIDGET_API_KEYandADMIN_API_KEYdifferent - Limit distribution: Only share
WIDGET_API_KEYwith trusted frontend deployments - Monitor usage: Watch for unexpected 401 responses indicating invalid keys
- Use HTTPS: Always transmit keys over encrypted connections
Error Responses
Missing or Invalid Key
401 Unauthorized
Admin Key Not Configured
503 Service Unavailable
Related Documentation
- Security Overview - Complete security features
- CORS Configuration - Cross-origin access control