Skip to content

feat(usage-api): make external endpoint to query usage#1285

Merged
icecrasher321 merged 6 commits intostagingfrom
feat/usage-api
Sep 8, 2025
Merged

feat(usage-api): make external endpoint to query usage#1285
icecrasher321 merged 6 commits intostagingfrom
feat/usage-api

Conversation

@icecrasher321
Copy link
Collaborator

Summary

External endpoint to fetch current period cost, limit, plan -- GET /api/users/me/usage-limits

Extends rate-limits endpoints.

Type of Change

  • New feature

Testing

curl -X GET -H "X-API-Key: YOUR_API_KEY" -H "Content-Type: application/json" https://sim.ai/api/users/me/usage-limits

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing
  • No new warnings introduced
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)

@vercel
Copy link

vercel bot commented Sep 8, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
sim Ready Ready Preview Comment Sep 8, 2025 11:27pm
1 Skipped Deployment
Project Deployment Preview Comments Updated (UTC)
docs Skipped Skipped Sep 8, 2025 11:27pm

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Edit Code Review Bot Settings | Greptile

@vercel vercel bot temporarily deployed to Preview – docs September 8, 2025 23:23 Inactive
@icecrasher321 icecrasher321 merged commit d357280 into staging Sep 8, 2025
6 checks passed
arenadeveloper02 pushed a commit to arenadeveloper02/p2-sim that referenced this pull request Sep 19, 2025
)

* feat(usage-api): make external endpoint to query usage

* add docs

* consolidate endpoints with rate-limits one

* update docs

* consolidate code

* remove unused route
@waleedlatif1 waleedlatif1 deleted the feat/usage-api branch September 25, 2025 22:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant