Skip to content

[Bug]: Failover does not trigger on Anthropic "insufficient_quota" due to HTTP 400 masking and missing keywords #23440

@smile-xuc

Description

@smile-xuc

Summary

When using Anthropic models (e.g., Claude Opus) and the account runs out of credits, the API returns an insufficient_quota error with an HTTP 400 status code. OpenClaw fails to trigger the fallback model chain and gets stuck.

Steps to reproduce

Steps to Reproduce:

  1. Configure an Anthropic model (e.g., anthropic/claude-sonnet-4-6-thinking) as the primary model in openclaw.json.
  2. Use an Anthropic API key that has run out of credits (zero balance).
  3. Configure one or more fallback models in the agents defaults (e.g., zai/glm-5).
  4. Send a prompt to the agent.

Expected behavior

OpenClaw should recognize the insufficient_quota error as a billing/rate-limit issue, cleanly abort the primary model attempt, and seamlessly fail over to the configured fallback models.

Actual behavior

OpenClaw receives the HTTP 400 error from Anthropic and hits a hardcoded if (status === 400) return "format"; check in the compiled source (pi-embedded-*.js). It incorrectly classifies the quota error as a Cloud Code Assist "format" error. The fallback failover process is bypassed, and the agent gets stuck without calling the fallback models.

Root Causes:

  1. HTTP 400 Masking in resolveFailoverReasonFromError:
    In pi-embedded-*.js, there is a hardcoded check:
    if (status === 400) return "format";
    This catches the Anthropic HTTP 400 quota error and incorrectly classifies it, preventing standard rate-limit/billing failover.

  2. Missing Keywords in ERROR_PATTERNS:
    The ERROR_PATTERNS.rateLimit array in pi-embedded-helpers-*.js lacks explicit string matches for "insufficient_quota" and "insufficient quota".

Proposed Fix:

  1. Update resolveFailoverReasonFromError to ensure HTTP 400 isn't blindly treated as a format error if a rate-limit/billing keyword is present:

    if (status === 400 && !classifyFailoverReason(getErrorMessage(err))) return "format";
  2. Add "insufficient_quota" and "insufficient quota" to the rateLimit (or billing) pattern array in ERROR_PATTERNS.

OpenClaw version

OpenClaw Version: 2026.2.19-2

Operating system

macOS 26.3 (25D125)

Install method

npm global

Logs, screenshots, and evidence

Impact and severity

No response

Additional information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingstaleMarked as stale due to inactivity

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions