Overview
API keys are the primary authentication method for programmatic access to Azen. Each key is scoped to an organization and can be configured with rate limits, expiration, and permissions.Creating API Keys
Access the console
Log in to the Azen console at azen.sh and navigate to your organization dashboard.
API Key Structure
API keys are stored with the following fields in the database schema:Key Fields
Frompackages/db/src/db/schema.ts:
Configuring Rate Limits
Token Bucket Algorithm
Azen uses a token bucket rate limiting algorithm:rateLimitMax: Maximum requests in the time window (default: 60)rateLimitTimeWindow: Time window in milliseconds (default: 60000 = 1 minute)refillInterval: How often tokens refill (optional)refillAmount: How many tokens to add on refill (optional)
Rate Limit Examples
Standard Rate Limit (60 req/min)
Standard Rate Limit (60 req/min)
High Throughput (1000 req/min)
High Throughput (1000 req/min)
Burst Allowance with Refill
Burst Allowance with Refill
No Rate Limit
No Rate Limit
Rate limit configuration is set during key creation and can be updated from the console.
Key Permissions
API keys can be scoped with specific permissions (stored in thepermissions field):
memory.read: List and retrieve memoriesmemory.write: Create new memoriesmemory.delete: Delete memoriesusage.read: View usage statistics
Permission scoping is enforced in the console. The API currently assumes full permissions for valid keys.
Key Expiration
Set an expiration date for temporary or time-limited keys:Key Metadata
Store additional context about keys using themetadata JSON field:
- Tracking key usage context
- Auditing key creation
- Identifying keys in logs
Monitoring API Keys
Track Usage
Monitor key usage from the console:- Total requests: Lifetime request count
- Last request: Timestamp of most recent API call
- Remaining tokens: Current rate limit token balance
View Activity
See detailed usage metrics:Revoking API Keys
Disable or delete
- Disable: Set
enabledtofalse(key can be re-enabled later) - Delete: Permanently remove the key from the database
Key Rotation Best Practices
Regular Rotation
Rotate keys every 90 days:Emergency Rotation
If a key is compromised:- Immediately disable the compromised key
- Create a new key with different settings
- Update all applications ASAP
- Audit logs to check for unauthorized access
- Delete the compromised key once migration is complete
Troubleshooting
Key Not Working (403)
Possible causes:- Key is disabled (
enabled: false) - Key has expired (
expiresAtin the past) - Key is not associated with a valid organization
- Key was deleted
Rate Limit Exceeded (429)
- Wait for rate limit to reset
- Implement exponential backoff
- Request higher rate limits from console
Key Not Found in Requests
Symptom: HTTP 401 “no api key” Solution: Ensure you’re sending theazen-api-key header:
Security Recommendations
Use Environment Variables
Never hardcode keys in source code. Use environment variables or secrets managers.
Separate Keys per Environment
Use different keys for development, staging, and production environments.
Rotate Regularly
Rotate keys every 90 days or after team member departures.
Monitor Activity
Regularly review key usage to detect anomalies or compromised keys.
Scope Permissions
Grant only the minimum permissions needed for each key’s purpose.
Set Expiration
Use short-lived keys for temporary access or third-party integrations.
Next Steps
Authentication Guide
Learn how to use API keys in requests
Rate Limits
Understand rate limiting in detail
Usage Tracking
Monitor API usage and quotas
Organizations
Understand organization-based access control

