fix(extra-usage): correct unit assumptions for usage API response#388
Merged
Conversation
The Anthropic usage API returns `extra_usage.used_credits` in cents (not dollars) and `extra_usage.utilization` as a percent 0-100 (not a 0-1 fraction). The current widget code assumed the inverse, which made: - ExtraUsageUtilization always clamp to 100.0% (multiplying a percent by 100 and clamping to [0,100]) - ExtraUsageRemaining always show $0.00 (subtracting cents from dollars goes negative, clamped to 0) Drop the `* 100` in ExtraUsageUtilization and divide `extraUsageUsed` by 100 in ExtraUsageRemaining so both widgets render real values. Verified locally against a live API response where util=6.74 and used=27087/limit=400000 — now renders "Overage: 6.8% | Overage Left: \$3,728.54" instead of "Overage: 100.0% | Overage Left: \$0.00".
Adjust extraUsageUsed fixtures to cents and extraUsageUtilization fixtures to 0-100 percentages so they exercise the corrected widget math. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Update fetch and prefetch fixtures to reflect used credits as cents and extra usage utilization as a 0-100 percentage. Clarify the UsageData comments to match the widget contract.
Owner
|
Thanks for the contribution here. The live API details you included were helpful. I pushed a small follow-up commit with minor test/contract tweaks so the source-layer fixtures and
The widget changes look good with that contract clarified. This will be included in the next release. |
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.
Summary
Fixes #387.
ExtraUsageRemaining:extraUsageUsedis in cents (not dollars), so divide by 100 before subtracting from the limit. Previously the widget subtracted a cents value from a dollars value, producing an inflated "Overage Left" amount.ExtraUsageUtilization:extraUsageUtilizationis already a percentage (0–100), not a fraction. Removed the erroneous* 100that caused the value to clamp to 100% almost immediately.Test plan
bun run lintpassesbun testpasses🤖 Generated with Claude Code