Overview
Azen supports two authentication methods:- API Key Authentication - For programmatic access to the API
- Session Authentication - For web console access (handled automatically)
API Key Authentication
All API requests must include an API key in theazen-api-key header.
Header Format
How Authentication Works
The authentication flow is implemented inauthMiddleware.ts:
Check for session authentication
The middleware first checks for an active user session (used by the web console).
Extract API key from header
If no session exists, the middleware extracts the
azen-api-key header from the request.Verify API key
The API key is verified using Better Auth’s
verifyApiKey method, which checks:- Key validity
- Rate limits
- Key expiration
- Organization association
Authentication Errors
Missing API Key (401)
Error: Noazen-api-key header provided
azen-api-key header in your request.
Invalid API Key (403)
Error: API key is invalid, expired, or disabled- Correctly copied (no extra spaces)
- Still active and not expired
- Associated with a valid organization
Rate Limited (429)
Error: API key has exceeded its rate limitSecurity Best Practices
Store Keys Securely
Rotate Keys Regularly
Use Key-Specific Permissions
When creating API keys, grant only the minimum permissions needed:- Read-only keys for monitoring and analytics
- Write-only keys for data ingestion services
- Full access keys only for trusted applications
API key permissions are configured in the console when creating or editing keys.
Organization Context
All authenticated requests are scoped to an organization:- API keys are tied to a specific organization (stored in
organizationIdmetadata) - Memories are isolated per organization
- Usage tracking is aggregated by organization
- Rate limits are enforced per organization
Testing Authentication
Test your authentication setup with a simple request:Next Steps
Create Memories
Start storing memories with your API key
Manage API Keys
Learn how to create and manage API keys
Rate Limits
Understand rate limiting and quotas
Error Handling
Handle authentication errors gracefully

