Skip to content

feat: add web endpoint fallback for cookie usage metrics on non-Claude-Code accounts#144

Open
GottenHeave wants to merge 2 commits intoXerxes-2:masterfrom
GottenHeave:fix-enterprise-usage
Open

feat: add web endpoint fallback for cookie usage metrics on non-Claude-Code accounts#144
GottenHeave wants to merge 2 commits intoXerxes-2:masterfrom
GottenHeave:fix-enterprise-usage

Conversation

@GottenHeave
Copy link
Copy Markdown

Problem

Accounts without Claude Code access (e.g. Enterprise, or any subscription lacking the Claude Code entitlement) return 403 Forbidden ("Claude Code requires a Pro or Max subscription") when fetching usage metrics from the OAuth endpoint (api.anthropic.com/api/oauth/usage). This causes the WebUI to show no utilization data for these cookies, even though the data is available via the claude.ai web endpoint.

Solution

  • Add fetch_web_usage() method to ClaudeWebState that bootstraps a web session and fetches usage from claude.ai/api/organizations/{org_uuid}/usage
  • Refactor fetch_usage_percent() to first attempt the OAuth endpoint, then automatically fall back to the web endpoint on failure
  • Extract shared usage JSON parsing into extract_usage_fields() helper (both endpoints return the same JSON structure)
  • Replace silent .ok()? calls with explicit match + warn! logging for better debuggability

How it works

  1. Try OAuth endpoint (works for accounts with Claude Code access)
  2. If that fails, fall back to claude.ai web endpoint via ClaudeWebState (works for all accounts with a valid session cookie)
  3. Parse the usage response with the shared helper

Both endpoints return the same JSON shape (five_hour, seven_day, seven_day_opus, seven_day_sonnet), so no additional parsing logic is needed.

@GottenHeave GottenHeave force-pushed the fix-enterprise-usage branch from 61f6627 to 306af92 Compare April 9, 2026 07:05
@LeenHawk
Copy link
Copy Markdown
Collaborator

LeenHawk commented Apr 10, 2026

wow, this is great

@LeenHawk LeenHawk requested a review from Xerxes-2 April 10, 2026 14:36
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.

2 participants