Overview
Azen automatically tracks all API usage for monitoring, billing, and analytics. Usage is aggregated per organization, API key, and route, with detailed metrics stored in Redis and Postgres.Usage Metrics
Tracked Operations
Azen tracks the following metrics for each API request:totalRequests: Total number of API requestssuccessCount: Successful requests (HTTP 2xx, 3xx)errorCount: Failed requests (HTTP 4xx, 5xx)memoryCount: Number of memories created (POST /memory)searchCount: Number of search queries (POST /memory/search)
Aggregation Levels
Metrics are aggregated by:- Organization: All usage for your organization
- API Key: Usage per individual API key
- Date: Daily granularity (YYYY-MM-DD format)
- Route Group:
memory_createormemory_search
Retrieving Usage Statistics
Get Usage Data
Response Format
Response (200 OK):Response Fields
range
start: First day of the 30-day period (YYYY-MM-DD)end: Last day (today)
labels
Array of 30 date strings (one per day) in chronological order.
series
Daily time series data aligned with labels:
memory_create: Memories created per daymemory_search: Search queries per daytotal: Total requests per daysuccess: Successful requests per dayerror: Failed requests per day
summary
Aggregated totals across the entire 30-day period.
The usage endpoint returns the last 30 days of data. Historical data beyond 30 days is preserved in the database but not returned by the API.
How Usage Tracking Works
Request Tracking Flow
Request enters middleware
The
trackUsage middleware intercepts requests to /api/v1/memory and /api/v1/memory/search.Extract context
Middleware extracts
userId, apiKeyId, organizationId from the authenticated request.Determine route group
Request is classified:
POST /api/v1/memory→memory_createPOST /api/v1/memory/search→memory_search
Implementation Reference
Fromapps/api/src/middlewares/trackUsage.ts:
Data Storage
Redis (Real-time)
- Purpose: Fast, atomic counters for live metrics
- TTL: 7 days (metrics automatically expire)
- Structure: Hash keys with counters per metric
Postgres (Long-term)
- Purpose: Persistent storage for analytics and billing
- Table:
api_usage - Granularity: Per organization, API key, date, and route group
packages/db/src/db/schema.ts):
Monitoring Usage
Dashboard Visualization
The console dashboard displays usage metrics as:- Time series charts: Daily request trends over 30 days
- Summary cards: Total requests, memories, searches
- Success rate: Percentage of successful vs. failed requests
- Per-key breakdown: Usage by individual API key
Query Historical Data
For custom analytics, query theapi_usage table directly:
Usage Alerts
High Error Rate
MonitorerrorCount vs. successCount. An error rate above 5% may indicate:
- Invalid authentication
- Rate limiting issues
- Malformed requests
- Service degradation
Unexpected Spikes
Sudden increases intotalRequests could signal:
- Legitimate growth
- Runaway processes (e.g., infinite loops)
- DDoS or abuse
Rate Limiting Impact
Usage tracking is separate from rate limiting, but they interact:- Rate limits are enforced per API key in real-time
- Usage tracking records all requests, including rate-limited ones
- Error count increments when requests are rate-limited (HTTP 429)
Privacy and Data Retention
What’s Tracked
- Request counts and timestamps
- Success/failure status
- Organization, user, and API key IDs
- Route groups (operation types)
What’s NOT Tracked
- Request payloads (memory content)
- Response bodies
- User IP addresses
- Query parameters
Azen does not log or store memory content in usage metrics. All tracking is aggregated and anonymized.
Data Retention
- Redis: 7 days (automatic expiration)
- Postgres: Indefinite (for billing and analytics)
- Console: Last 30 days displayed by default
Troubleshooting
Missing Usage Data
Symptom: Usage endpoint returns zeros or empty series Possible causes:- No API requests have been made in the last 30 days
- Requests were made with a different organization’s API key
- Redis or Postgres sync failed
Incorrect Counts
Symptom: Usage counts don’t match expected values Possible causes:- Failed requests are counted in
errorCount, not inmemoryCount/searchCount - Multiple API keys in the same organization (check per-key breakdown)
- Background sync delay (Redis → Postgres)
Background Sync Worker
Usage data flows from Redis to Postgres via a background worker: Fromapps/api/src/workers/syncWorker.ts:
The sync worker runs every 60 seconds, so there may be a slight delay between Redis and Postgres data.
Next Steps
Rate Limits
Understand how rate limiting affects usage
Managing API Keys
Configure rate limits for your API keys
Organizations
Learn about organization-level usage aggregation
API Reference
Explore all API endpoints

