[BUG] Model discovery incompatible with hybrid claude.ai/gateway authentication
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?
When using Claude Code with a model gateway, where Claude Code is configured to authenticate to both the model gateway and claude.ai (such as LiteLLM following this guide), model discovery does not function even if CLAUDE_CODE_ENABLE_GATEWAY_MODEL_DISCOVERY=1 is set.
In this configuration, the model proxy authentication token is supplied using ANTHROPIC_CUSTOMER_HEADER: "x-litellm-api-key: Bearer ....", and Claude Code handles the Anthropic Claude.ai credential. Although the docs state that the value of custom headers set in ANTHROPIC_CUSTOMER_HEADER will be included in the request, it appears as if Claude Code does not attempt model discovery unless ANTHROPIC_AUTH_TOKEN or ANTHROPIC_API_KEY is also set. This is undesirable, as we want Claude Code to be using OAuth to Claude.ai, not a static token, but we still want model discovery to occur.
What Should Happen?
So long as CLAUDE_CODE_ENABLE_GATEWAY_MODEL_DISCOVERY=1 is set, model discovery should occur. The presence or absence of ANTHROPIC_AUTH_TOKEN or ANTHROPIC_API_KEY should be irrelevant.
Error Messages/Logs
None
Steps to Reproduce
- Configure a model proxy following this guide
- Configure Claude Code to connect through this model proxy, and to use model discovery
- Observe that model discovery was not used (e.g. by looking at
/model, or by looking at model proxy logs) - Configure Claude Code to use
ANTHROPIC_AUTH_TOKEN - Observe that model discovery now works
Claude Model
None
Is this a regression?
No, this never worked
Last Working Version
_No response_
Claude Code Version
2.1.179
Platform
Anthropic API
Operating System
Ubuntu/Debian Linux
Terminal/Shell
Other
Additional Information
_No response_
This issue has 1 comment on GitHub. Read the full discussion on GitHub ↗