mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-06 02:48:13 +00:00
fix(anthropic): honor custom-base bearer auth for messages
This commit is contained in:
parent
c2141b1113
commit
ed127727c4
2 changed files with 28 additions and 1 deletions
|
|
@ -172,7 +172,11 @@ class AnthropicMessagesConfig(BaseAnthropicMessagesConfig):
|
|||
headers, api_key = optionally_handle_anthropic_oauth(headers=headers, api_key=api_key)
|
||||
|
||||
if "x-api-key" not in headers and "authorization" not in headers:
|
||||
auth_header = AnthropicModelInfo.get_auth_header(api_key)
|
||||
auth_header = AnthropicModelInfo.get_auth_header(
|
||||
api_key=api_key,
|
||||
api_base=api_base if api_base is not None else litellm_params.get("api_base"),
|
||||
use_bearer_for_custom_base=bool(litellm_params.get("use_bearer_for_custom_base", False)),
|
||||
)
|
||||
if auth_header is not None:
|
||||
headers.update(auth_header)
|
||||
if "anthropic-version" not in headers:
|
||||
|
|
|
|||
|
|
@ -386,6 +386,29 @@ class TestPassthroughOAuth:
|
|||
assert updated_headers["x-api-key"] == FAKE_REGULAR_KEY
|
||||
assert "authorization" not in updated_headers
|
||||
|
||||
def test_passthrough_custom_base_uses_bearer_from_litellm_params(self):
|
||||
from litellm.llms.anthropic.experimental_pass_through.messages.transformation import (
|
||||
AnthropicMessagesConfig,
|
||||
)
|
||||
|
||||
config = AnthropicMessagesConfig()
|
||||
|
||||
updated_headers, _ = config.validate_anthropic_messages_environment(
|
||||
headers={},
|
||||
model="claude-sonnet-4-5-20250929",
|
||||
messages=[{"role": "user", "content": "Hello"}],
|
||||
optional_params={},
|
||||
litellm_params={
|
||||
"api_base": "https://custom-gateway.example.com",
|
||||
"use_bearer_for_custom_base": True,
|
||||
},
|
||||
api_key="custom-api-key",
|
||||
api_base=None,
|
||||
)
|
||||
|
||||
assert updated_headers["authorization"] == "Bearer custom-api-key"
|
||||
assert "x-api-key" not in updated_headers
|
||||
|
||||
|
||||
class TestIsAnthropicOAuthKey:
|
||||
"""Tests for is_anthropic_oauth_key helper function."""
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue