Skip to content

Backend: Add API Key Usage Analytics and Quota Management Dashboard #471

Description

@Smartdevs17

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    200-points200 point issuedrips-waveIssues in the Drips Wave programhighHigh complexity issue

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions