Fix Claude adapter: parse the real claude.ai usage response - #2
Merged
Merged
Conversation
Verified against a live capture: the usage endpoint is the first probe candidate after all, but validation failed because unused windows arrive as explicit nulls (seven_day_opus: null) where the schema only allowed absence — exactly the honest endpoint_not_verified failure by design, just for the wrong reason. The response also carries a limits[] array — the canonical list the usage page itself renders, including model-scoped weekly limits — so that is now the primary schema variant (session / weekly_all / weekly_scoped lanes with the model display name in the label). The top-level windows shape remains as a null-tolerant fallback variant. Adapter version bumped to 2; the live shape is a recorded fixture.
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.
What happened
First live test of v0.1 showed the Claude card failing with
endpoint_not_verified. A DevTools capture from a real account revealed two things:GET /api/organizations/<org>/usage(the first probe candidate). Validation failed because unused windows come back as explicitnulls ("seven_day_opus": null) where the schema only allowed the key to be absent. The honest-failure design worked exactly as intended — no wrong number was ever shown — but the schema was too strict.limits[]array that is clearly the canonical list the usage page itself renders:session,weekly_all, and model-scopedweekly_scopedentries with percent used, reset timestamps, and the scoped model's display name.The fix
limits[]is now the primary schema variant (org_usage_limits): each entry becomes a lane, with model-scoped weeklies labeledWeekly (<model>).org_usage_windows) in case older/other accounts serve it withoutlimits.tests/fixtures/claude/usage.limits.json, plus a null-window regression case in the windows fixture.Verification
npm run cigreen: typecheck + 55 tests + build.Session (5h)87%,Weekly (all models)95%,Weekly (Fable)93% — matching the capturing account's actual usage page.🤖 Generated with Claude Code
https://claude.ai/code/session_015gwwHsEgVxtmfRn3dEkBif
Generated by Claude Code