Skip to content

Fix: support claude code auth via subscription (anthropic)#14821

Merged
2 commits merged intoBerriAI:mainfrom
hazyone:fix-13380
Sep 24, 2025
Merged

Fix: support claude code auth via subscription (anthropic)#14821
2 commits merged intoBerriAI:mainfrom
hazyone:fix-13380

Conversation

@hazyone
Copy link
Copy Markdown
Contributor

@hazyone hazyone commented Sep 23, 2025

Support claude code auth via subscription

There is a problem, when you have max claude code subscription and want to collect metrics for it, overriding base url to : http://localhost:4000/anthropic, you would get 401 errors, because of x-api-key header

Relevant issues

"Fixes #13380"

Pre-Submission checklist

Please complete all items before asking a LiteLLM maintainer to review your PR

  • I have Added testing in the tests/litellm/ directory, Adding at least 1 test is a hard requirement - see details
  • I have added a screenshot of my new test passing locally
  • My PR passes all unit tests on make test-unit
  • My PR's scope is as isolated as possible, it only solves 1 specific problem

Type

🐛 Bug Fix

Changes

We now replace the x-api-key header only if two conditions are met simultaneously:

  • The request headers are missing the Authorization header.
  • The LiteLLM interface includes ANTHROPIC_API_KEY.

@vercel
Copy link
Copy Markdown

vercel bot commented Sep 23, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
litellm Ready Ready Preview Comment Sep 23, 2025 6:19pm

@CLAassistant
Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@hazyone
Copy link
Copy Markdown
Contributor Author

hazyone commented Sep 23, 2025

Screenshot 2025-09-23 at 20 15 26

@hazyone
Copy link
Copy Markdown
Contributor Author

hazyone commented Sep 23, 2025

there are 3 test failed, but is not related to this tiny fix

@ghost ghost merged commit 37ea89e into BerriAI:main Sep 24, 2025
3 of 7 checks passed
@ghost
Copy link
Copy Markdown

ghost commented Sep 24, 2025

could you share a tutorial for how you're running a claude code max subscription through litellm? i think others would find this helpful as well @hazyone

@hazyone hazyone deleted the fix-13380 branch September 24, 2025 11:19
ishaan-jaff added a commit that referenced this pull request Sep 28, 2025
This reverts commit 37ea89e, reversing
changes made to aede742.
@ishaan-jaff
Copy link
Copy Markdown
Contributor

@hazyone I needed to revert this, happy to help add it back in once the test is fixed. Please make sure this passes https://app.circleci.com/pipelines/github/BerriAI/litellm/43730/workflows/7dc22f65-f5dc-4192-b381-7d2b2f0e1f5e/jobs/707229/tests#failed-test-0

@yoosful
Copy link
Copy Markdown

yoosful commented Oct 31, 2025

Hey @hazyone and litellm team, do you plan to work on this again since it got reverted?

ric03uec pushed a commit to ric03uec/litellm that referenced this pull request Nov 2, 2025
- Only inject x-api-key header when client doesn't provide authorization or x-api-key
- Enables Claude Code OAuth flow while maintaining API key fallback
- Based on reverted PR BerriAI#14821 (commit 96aed6a)
rcII pushed a commit to jamraca/litellm that referenced this pull request Dec 16, 2025
Implements OAuth pass-through for Anthropic proxy endpoint, allowing
Claude Code subscription users to authenticate via OAuth tokens without
requiring an API key.

Changes:
- Modified anthropic_proxy_route to conditionally inject x-api-key header
- Only injects x-api-key when BOTH Authorization and x-api-key headers are missing
- Maintains backward compatibility with API key authentication
- Enables OAuth tokens (sk-ant-oat01-*) to pass through untouched

Testing:
- Added comprehensive unit tests covering all authentication scenarios:
  * OAuth token priority (Authorization header)
  * Client API key priority (x-api-key header)
  * Server API key fallback
  * No authentication scenarios
  * Multiple auth headers present
  * Case-insensitive header checking
- All tests use mocks (no real API calls)

Implementation aligns with previously approved PR BerriAI#14821 logic.

Fixes BerriAI#13380
Supersedes BerriAI#14821
pkieszcz added a commit to Bitropy/litellm that referenced this pull request Mar 19, 2026
Client-provided credentials now take precedence over server credentials
in the /anthropic/ passthrough endpoint. This enables mixed mode where:

1. Client sends x-api-key → forwarded as-is (user pays via own API key)
2. Client sends Authorization → forwarded as-is (user pays via OAuth/Max)
3. No client credentials + server ANTHROPIC_API_KEY → server key used
4. No client credentials + no server key → no credentials forwarded

Previously the server always sent x-api-key (even literal "None" when
unconfigured), overwriting any client-provided credentials and breaking
Claude Code Max (OAuth) and BYOK scenarios.

Supersedes the simpler one-liner from d742c76 on v1.81.12-stable-patched.
Based on the approach from PR BerriAI#20429 (closed) and reverted PR BerriAI#14821.
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature]: Support for pass-through OAuth for Anthropic

4 participants