Skip to content

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

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

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
Contributor

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
Contributor

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 runtime: loop, agent_init, prompt builder, context-compression, responses endpoint 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.

@teknium1

teknium1 commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

Fixed and merged via PR #56128 (rebase-merged, commit ea9e8d6 — your authorship preserved in git history).

"out of extra usage" (Anthropic OAuth Pro/Max overage bucket depleted) was misclassifying as a generic format_error — non-retryable with no credential rotation. It's now in _BILLING_PATTERNS, so it classifies as billing: non-retryable, rotates credential, falls back, and surfaces Anthropic-specific guidance (claude.ai/settings/usage + cycle-reset).

You were the earliest of four independent PRs submitting this exact fix — thanks for catching it first.

@teknium1 teknium1 closed this Jul 1, 2026
waefrebeorn pushed a commit to waefrebeorn/slermes that referenced this pull request Jul 2, 2026
Jasper6439 pushed a commit to Jasper6439/hermes-agent that referenced this pull request Jul 5, 2026
habarmc1223-sudo pushed a commit to habarmc1223-sudo/hermes-agent-fluxmem that referenced this pull request Jul 8, 2026
santhreal pushed a commit to santhreal/hermes-agent that referenced this pull request Jul 13, 2026
Gravezzz pushed a commit to Gravezzz/hermes-agent that referenced this pull request Jul 21, 2026
leewenjie pushed a commit to leewenjie/hermes-agent that referenced this pull request Aug 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint 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.

4 participants