claude-code - 💡(How to fix) Fix [FEATURE] Support auth fallback when primary provider returns 429 [1 comments, 2 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
anthropics/claude-code#46848Fetched 2026-04-12 13:31:28
View on GitHub
Comments
1
Participants
2
Timeline
4
Reactions
0
Timeline (top)
labeled ×3commented ×1

Fix Action

Fix / Workaround

Current workaround:
Alias two launch commands with different env vars and manually quit + /resume when budget is hit.

Current workaround:
Alias two launch commands with different env vars and manually quit + /resume when budget is hit.

RAW_BUFFERClick to expand / collapse

Preflight Checklist

  • I have searched existing requests and this feature hasn't been requested yet
  • This is a single feature request (not multiple features)

Problem Statement

When using Claude Code behind an enterprise proxy that returns 429 when budget is exhausted, it would be useful to have automatic fallback to a secondary auth method without requiring a session restart.

Current behavior:

  • 429 from the enterprise auth provider blocks all requests
  • User must quit, restart with a different API key, and /resume

Desired behavior:

  • Configure a fallback API key via env var (e.g., CLAUDE_FALLBACK_API_KEY)
  • On 429 from primary auth, automatically switch to fallback mid-session
  • No restart needed — conversation context preserved

Current workaround:
Alias two launch commands with different env vars and manually quit + /resume when budget is hit.

Proposed Solution

Desired behavior:

  • Configure a fallback API key via env var (e.g., CLAUDE_FALLBACK_API_KEY)
  • On 429 from primary auth, automatically switch to fallback mid-session
  • No restart needed — conversation context preserved

Alternative Solutions

Current workaround:
Alias two launch commands with different env vars and manually quit + /resume when budget is hit.

Priority

Medium - Would be very helpful

Feature Category

API and model interactions

Use Case Example

No response

Additional Context

No response

extent analysis

TL;DR

Implement a fallback mechanism to switch to a secondary API key when the primary key's budget is exhausted, using an environment variable like CLAUDE_FALLBACK_API_KEY.

Guidance

  • Introduce a new environment variable CLAUDE_FALLBACK_API_KEY to store the secondary API key.
  • Modify the authentication logic to detect 429 responses from the primary auth provider and automatically switch to the fallback API key.
  • Ensure conversation context is preserved during the switch to maintain a seamless user experience.
  • Consider implementing a retry mechanism to handle temporary budget exhaustion or network issues.

Example

import os

# Assuming an existing auth function that takes an API key
def authenticate(api_key):
    # Authentication logic here
    pass

# Get primary and fallback API keys from environment variables
primary_api_key = os.environ.get('CLAUDE_API_KEY')
fallback_api_key = os.environ.get('CLAUDE_FALLBACK_API_KEY')

# Authenticate with primary API key
try:
    authenticate(primary_api_key)
except Exception as e:
    # Check if 429 response and switch to fallback API key
    if e.status_code == 429:
        authenticate(fallback_api_key)

Notes

This solution assumes that the existing authentication logic can be modified to handle the fallback mechanism. Additionally, the implementation details may vary depending on the specific programming language and framework used.

Recommendation

Apply workaround: Implement the proposed solution using the CLAUDE_FALLBACK_API_KEY environment variable to provide a seamless fallback experience for users.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING