Context
Merchants need visibility into their API consumption to manage costs and plan capacity. AgenticPay needs to enforce fair usage.
Current Limitation/Problem
API keys have no usage tracking or quota enforcement. There is no way for merchants to monitor their API call volume or for the platform to throttle abusive usage.
Expected Outcome
API key usage analytics with real-time counters, daily/weekly/monthly breakdowns, quota limits with automatic enforcement, and alerting.
Acceptance Criteria
- Track API calls per key: endpoint, status code, latency, payload size
- Real-time usage dashboard with charts (requests/min, error rate, p50/p95 latency)
- Configurable quota limits per key (requests/hour, requests/day)
- Automatic 429 response when quota exceeded, with Retry-After header
- Quota increase request workflow with admin approval
- Usage export as CSV for billing/invoicing
- Alert at 50%, 80%, 100% quota consumption
- Monthly usage summary emailed to key owner
Technical Scope
backend/src/middleware/api-usage-tracker.ts - tracking middleware
backend/src/services/keys/quota-manager.ts - quota enforcement
- Redis sorted sets and counters for real-time usage
- Prisma:
ApiKeyUsage, ApiKeyQuota models
- Frontend:
/dashboard/developers/api-keys/{id}/usage - usage UI
- Edge cases: burst handling, distributed counter consistency, quota reset boundaries
Context
Merchants need visibility into their API consumption to manage costs and plan capacity. AgenticPay needs to enforce fair usage.
Current Limitation/Problem
API keys have no usage tracking or quota enforcement. There is no way for merchants to monitor their API call volume or for the platform to throttle abusive usage.
Expected Outcome
API key usage analytics with real-time counters, daily/weekly/monthly breakdowns, quota limits with automatic enforcement, and alerting.
Acceptance Criteria
Technical Scope
backend/src/middleware/api-usage-tracker.ts- tracking middlewarebackend/src/services/keys/quota-manager.ts- quota enforcementApiKeyUsage,ApiKeyQuotamodels/dashboard/developers/api-keys/{id}/usage- usage UI