From 56df59ff860c31e95c4c7810e0b98986ee1f1218 Mon Sep 17 00:00:00 2001 From: null Date: Sun, 24 May 2026 19:22:18 -0500 Subject: [PATCH] just one network call to api.anthropic.com/api/oauth/usage using the local OAuth token, and nothing else for Anthropic. --- backend/app/services/provider_usage.py | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/backend/app/services/provider_usage.py b/backend/app/services/provider_usage.py index 32d9a51..fe52ce0 100644 --- a/backend/app/services/provider_usage.py +++ b/backend/app/services/provider_usage.py @@ -1023,10 +1023,23 @@ async def _do_fetch_provider_usage( error="No API key configured.", ) + elif local_oauth: + # Local Claude session is the primary source — use the subscription + # endpoint only. Skipping /v1/models eliminates the sequential + # same-IP request that caused the subscription endpoint to 429. + subscription_attempted = True + result = ProviderUsageLive( + provider=provider, account_key=account_key, + checked_at=utcnow(), reachable=True, + ) + sub_windows = await _fetch_anthropic_subscription(local_oauth) + if sub_windows: + result.subscription_windows = sub_windows + else: + result.error = "No subscription data returned." + elif api_key and effective_session_key: - # Fire both calls concurrently — halves latency and eliminates the - # sequential back-to-back requests to api.anthropic.com that caused - # the subscription endpoint to 429 on every initial load. + # No local OAuth — fire API key + session key calls concurrently. subscription_attempted = True result, sub_windows = await asyncio.gather( _fetch_anthropic(api_key, base_url), @@ -1043,7 +1056,7 @@ async def _do_fetch_provider_usage( result = await _fetch_anthropic(api_key, base_url) else: - # OAuth token only — no API key configured + # session_key only, no local OAuth, no API key subscription_attempted = True result = ProviderUsageLive( provider=provider, account_key=account_key,