feat(usage-api): make external endpoint to query usage#1285
feat(usage-api): make external endpoint to query usage#1285icecrasher321 merged 6 commits intostagingfrom
Conversation
There was a problem hiding this comment.
Greptile Summary
This PR introduces a new external API endpoint /api/users/me/usage-limits that consolidates rate limiting and usage information into a single response. The changes include:
New External API Endpoint: The main addition is /api/users/me/usage-limits which provides comprehensive usage data including current period costs, usage limits, subscription plans, and rate limit status for both sync and async operations. This endpoint uses hybrid authentication supporting session tokens, API keys, and internal JWTs.
Enhanced Usage Calculation Logic: A new function getEffectiveCurrentPeriodCost() was added to the billing core module that implements different cost calculation strategies based on subscription types. For Free/Pro users, it returns individual usage costs, while for Team/Enterprise users, it pools costs across all organization members by querying multiple user IDs using the inArray operator.
API Consolidation: The existing /api/users/me/rate-limit endpoint was completely removed and its functionality absorbed into the new unified endpoint. This reduces API surface area while providing more comprehensive data in a single call.
Documentation and UI Updates: The PR includes updated documentation explaining the new endpoint's usage, authentication requirements, and response structure. Example cURL commands in the deployment modal UI were also updated to reference the new endpoint.
Supporting Infrastructure: A separate /api/users/me/usage endpoint was added to provide just the usage portion of the data, likely for internal use, following the established pattern of granular API endpoints.
The changes integrate well with the existing usage monitoring system documented in usage-monitor.ts, extending the external API capabilities while maintaining consistency with internal usage calculations and billing logic.
Confidence score: 4/5
- This PR is generally safe to merge with standard review attention
- Score reflects well-structured code following established patterns but involves API changes that affect external integrations
- Pay close attention to the new billing logic in
getEffectiveCurrentPeriodCost()function and endpoint consolidation
6 files reviewed, no comments
Summary
External endpoint to fetch current period cost, limit, plan -- GET /api/users/me/usage-limits
Extends rate-limits endpoints.
Type of Change
Testing
Checklist