mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-09 03:18:44 +00:00
Fix get_complete_url to honour ANTHROPIC_BASE_URL in experimental passthrough
Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
b7e2269942
commit
f784da41af
2 changed files with 25 additions and 2 deletions
|
|
@ -23,7 +23,6 @@ from ...common_utils import (
|
|||
optionally_handle_anthropic_oauth,
|
||||
)
|
||||
|
||||
DEFAULT_ANTHROPIC_API_BASE = "https://api.anthropic.com"
|
||||
DEFAULT_ANTHROPIC_API_VERSION = "2023-06-01"
|
||||
|
||||
|
||||
|
|
@ -127,7 +126,7 @@ class AnthropicMessagesConfig(BaseAnthropicMessagesConfig):
|
|||
litellm_params: dict,
|
||||
stream: Optional[bool] = None,
|
||||
) -> str:
|
||||
api_base = api_base or DEFAULT_ANTHROPIC_API_BASE
|
||||
api_base = AnthropicModelInfo.get_api_base(api_base)
|
||||
if not api_base.endswith("/v1/messages"):
|
||||
api_base = f"{api_base}/v1/messages"
|
||||
return api_base
|
||||
|
|
|
|||
|
|
@ -1107,3 +1107,27 @@ class TestPassthroughAuthToken:
|
|||
|
||||
assert updated_headers["x-api-key"] == FAKE_REGULAR_KEY
|
||||
assert "authorization" not in updated_headers
|
||||
|
||||
def test_passthrough_get_complete_url_honours_base_url_env(self):
|
||||
"""get_complete_url should use ANTHROPIC_BASE_URL when api_base is None."""
|
||||
from unittest.mock import patch as mock_patch
|
||||
|
||||
from litellm.llms.anthropic.experimental_pass_through.messages.transformation import (
|
||||
AnthropicMessagesConfig,
|
||||
)
|
||||
|
||||
config = AnthropicMessagesConfig()
|
||||
with mock_patch.dict(
|
||||
"os.environ",
|
||||
{"ANTHROPIC_BASE_URL": "https://custom.example.com"},
|
||||
clear=True,
|
||||
):
|
||||
url = config.get_complete_url(
|
||||
api_base=None,
|
||||
api_key=FAKE_REGULAR_KEY,
|
||||
model="claude-sonnet-4-5-20250929",
|
||||
optional_params={},
|
||||
litellm_params={},
|
||||
)
|
||||
|
||||
assert url == "https://custom.example.com/v1/messages"
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue