Skip to content

fix(classifier): treat Anthropic "out of extra usage" 400 as billing#11736

Open
charleneleong-ai wants to merge 1 commit into
NousResearch:mainfrom
charleneleong-ai:fix/classifier-anthropic-extra-usage
Open

fix(classifier): treat Anthropic "out of extra usage" 400 as billing#11736
charleneleong-ai wants to merge 1 commit into
NousResearch:mainfrom
charleneleong-ai:fix/classifier-anthropic-extra-usage

Conversation

@charleneleong-ai

Copy link
Copy Markdown

Anthropic returns HTTP 400 with "You're out of extra usage. Add more at claude.ai/settings/usage and keep going." when a user's extra-usage allowance is depleted. This wording is not in _BILLING_PATTERNS in agent/error_classifier.py, so classify_api_error falls through _classify_400 to the generic format_error path (retryable=False, should_fallback=False). The agent aborts instead of engaging the configured fallback chain (fallback_providers / fallback_model).

Fix: add "out of extra usage" to _BILLING_PATTERNS. Now classified as FailoverReason.billingshould_fallback=True, matching how other providers' billing-exhaustion messages are handled.

Repro

Primary Anthropic model with depleted extra usage + Gemini fallback configured:

⚠️  API call failed (attempt 1/3): BadRequestError [HTTP 400]
   🔌 Provider: anthropic  Model: claude-opus-4-6
   📝 Error: HTTP 400: You're out of extra usage. Add more at claude.ai/settings/usage and keep going.
❌ Non-retryable client error (HTTP 400). Aborting.

After the fix the same error triggers the fallback chain and the agent continues on the fallback provider.

Test plan

  • Added test_400_anthropic_extra_usage_exhausted in tests/agent/test_error_classifier.py asserting reason == billing, should_fallback is True, retryable is False.
  • pytest tests/agent/test_error_classifier.py — 98 passed.
  • Verified locally: after restarting the gateway with the patch, the same 400 advances to the configured fallback provider instead of aborting.

Anthropic returns HTTP 400 with "You're out of extra usage. Add more at
claude.ai/settings/usage and keep going." when the account's extra-usage
allowance is depleted. The existing _BILLING_PATTERNS list did not
include this wording, so classify_api_error fell through to generic
format_error — non-retryable and should_fallback=False — causing the
agent to abort instead of engaging the configured fallback chain.

Add the pattern and a regression test covering the exact Anthropic body.
@charleneleong-ai charleneleong-ai force-pushed the fix/classifier-anthropic-extra-usage branch from e574a7e to a62928a Compare April 17, 2026 18:42
@trevorgordon981

Copy link
Copy Markdown

LGTM. Clean, focused fix. The new pattern matches the shape of other entries in _BILLING_PATTERNS and the test pins the classification contract (reason, fallback, retryable) explicitly.

@alt-glitch alt-glitch added type/bug Something isn't working P2 Medium — degraded but workaround exists comp/agent Core agent loop, run_agent.py, prompt builder provider/anthropic Anthropic native Messages API labels Apr 24, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

Related to #13170 — identical fix (add 'out of extra usage' to _BILLING_PATTERNS). This PR and #13170 are competing implementations.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/agent Core agent loop, run_agent.py, prompt builder P2 Medium — degraded but workaround exists provider/anthropic Anthropic native Messages API type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants