Skip to content

The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]

Fix get_complete_url to honour ANTHROPIC_BASE_URL in experimental passthrough

Devin Petersohnf784da41af57
diff --git a/litellm/llms/anthropic/experimental_pass_through/messages/transformation.py b/litellm/llms/anthropic/experimental_pass_through/messages/transformation.py
index 8e7c8506278..6f1a7718fc5 100644
--- a/litellm/llms/anthropic/experimental_pass_through/messages/transformation.py
+++ b/litellm/llms/anthropic/experimental_pass_through/messages/transformation.py
@@ -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
diff --git a/tests/test_litellm/llms/anthropic/test_anthropic_common_utils.py b/tests/test_litellm/llms/anthropic/test_anthropic_common_utils.py
index dd5c49258ee..22470b93540 100644
--- a/tests/test_litellm/llms/anthropic/test_anthropic_common_utils.py
+++ b/tests/test_litellm/llms/anthropic/test_anthropic_common_utils.py
@@ -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"