[BUG] Excessive Retry Delays When Fast Model Returns 401 - No Configurable Fallback
Preflight Checklist
- [x] I have searched existing issues and this hasn't been reported yet
- [x] This is a single bug report (please file separate reports for different bugs)
- [x] I am using the latest version of Claude Code
What's Wrong?
Excessive Retry Delays When Fast Model Returns 401 - No Configurable Fallback
Environment
Claude Code Version: 2.0.8, 2.0.29
OS: Linux (RHEL-based)
Node Version: v22.15.0
Custom Endpoint: Enterprise API proxy
Description
When Claude Code's preferred "fast" model is unauthorized (HTTP 401), it performs 60+ seconds of retry attempts before falling back to an authorized model. There is no configuration option to skip the fast model or customize the fallback behavior, causing severe performance degradation for every operation.
Actual Behavior
Every single operation experiences 60+ second delays due to:
- Claude Code attempts claude-3-5-haiku-20241022 for pre-flight checks
- Receives 401 Unauthorized
- Retries with exponential backoff ~20 times over 60 seconds
- Finally falls back to claude-sonnet-3.7
- Hardcoded model identifier: Claude Code uses claude-3-5-haiku-20241022 internally, ignoring preferredModels.fast setting for certain operations
- No fail-fast on 401: Unlike 404/500 errors, 401s trigger aggressive retry logic meant for transient auth failures, not permanent authorization issues
- No model allowlist validation: Claude Code doesn't pre-validate which models are available at the endpoint
- Model naming mismatch: Custom endpoints may use different naming conventions:
Anthropic public API: claude-3-5-haiku-20241022
Custom proxies: claude-haiku-3, anthropic.claude-3-haiku-20240307-v1:0
Related Issues
- Deprecated ANTHROPIC_SMALL_FAST_MODEL environment variable with no documented replacement
- preferredModels.fast appears to be ignored for internal operations
- Custom endpoints often use different model naming than Anthropic's public API
What Should Happen?
Expected Behavior
When a model returns 401 (Unauthorized):
- Fail fast after 1-2 attempts (not 20+)
- Immediately fall back to configured alternative model
- Remember the failure and stop attempting that model for the session
- Allow users to configure which models to attempt via preferredModels or similar
Error Messages/Logs
[log_d90d82] sending request {
url: 'https://foo.com/v1/messages?beta=true',
model: 'claude-3-5-haiku-20241022',
max_tokens: 512
}
[log_d90d82] post failed with status 401 in 211ms
[log_3e59a9] post failed with status 401 in 63ms
[log_03324e] post failed with status 401 in 62ms
[log_6d424e] post failed with status 401 in 68ms
[log_670c84] post failed with status 401 in 61ms
[log_32c409] post failed with status 401 in 72ms
[log_d4f255] post failed with status 401 in 98ms
[log_42a0d7] post failed with status 401 in 93ms
[... 20+ more attempts over 60 seconds ...]
[log_cbf1e4] sending request {
url: 'https://foo.com/v1/messages?beta=true',
model: 'claude-sonnet-3.7'
}
[log_cbf1e4] post succeeded with status 200 in 2957ms
Steps to Reproduce
Set up an environment where the "fast" api is unreachable.
Ask the model to preform an action that will trigger a pre-flight request, such as running a bash command.
Claude Model
Sonnet (default)
Is this a regression?
I don't know
Last Working Version
_No response_
Claude Code Version
2.0.29
Platform
AWS Bedrock
Operating System
Other Linux
Terminal/Shell
Other
Additional Information
_No response_
This issue has 4 comments on GitHub. Read the full discussion on GitHub ↗