Repository navigation
feat(usage): allow callers to read own usage with no-store and window resets (#513) - #568
Open
sparkysolutions10-pixel wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Fixes #513.
Summary of Changes
Callers previously had no way to inspect their remaining quota or window reset timing until hitting an overage or 402 rejection.
This PR implements the caller-facing usage inspection endpoints in accordance with all acceptance criteria:
GET /usageandGET /usage/me):Authorization: Bearer <key>) to read their own usage.req.apiKey.id). Any query string parameters (such as?keyId=...), URL parameters, or body parameters are completely ignored, guaranteeing zero cross-key leakage.getUsageSummaryInternal()computation and Redis counters used bycheckQuota()insrc/x402/metering.ts.dailyResetsAt,monthlyResetsAt,resets: { daily, monthly }, andresetsInSeconds: { daily, monthly }countdowns toUsageSummary.no-store):Cache-Control: no-storeon the response so shared or intermediary caches never retain per-caller usage./usage(alias for/usage/me) and updatedUsageResponseschema inopenapi.yamland generatedopenapi.json.src/__tests__/callerUsage.test.tsverifying 401 unauthenticated handling, proper usage extraction with reset countdowns andno-store, and cross-key parameter isolation.Testing
npx vitest run src/__tests__/callerUsage.test.ts(3/3 passed)npx vitest run src/__tests__/usage.test.ts tests/openapi.test.ts(14/14 passed)