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]
Python ai-gatewayanthropicazure-openaibedrockgatewaylangchainlitellmllmllm-gatewayllmopsmcp-gatewayopenaiopenai-proxyrustrust-aivertex-ai
[Fix] v1/messages endpoint always uses us-central1 with vertex_ai-anthropic models (#11831)
Ishaan Jaff6ffebe7394e8
diff --git a/litellm/llms/vertex_ai/vertex_ai_partner_models/anthropic/experimental_pass_through/transformation.py b/litellm/llms/vertex_ai/vertex_ai_partner_models/anthropic/experimental_pass_through/transformation.pyindex 7ab363886b0..cb2a96e3bf2 100644--- a/litellm/llms/vertex_ai/vertex_ai_partner_models/anthropic/experimental_pass_through/transformation.py+++ b/litellm/llms/vertex_ai/vertex_ai_partner_models/anthropic/experimental_pass_through/transformation.py@@ -40,6 +40,14 @@ class VertexAIPartnerModelsAnthropicMessagesConfig(AnthropicMessagesConfig, Vertor get_secret_str("VERTEXAI_CREDENTIALS"))+ vertex_ai_location = (+ litellm_params.pop("vertex_location", None)+ or litellm_params.pop("vertex_ai_location", None)+ or litellm.vertex_location+ or get_secret_str("VERTEXAI_LOCATION")+ or get_secret_str("VERTEX_LOCATION")+ )+access_token, project_id = self._ensure_access_token(credentials=vertex_credentials,project_id=vertex_ai_project,@@ -50,7 +58,7 @@ class VertexAIPartnerModelsAnthropicMessagesConfig(AnthropicMessagesConfig, Vertapi_base = self.get_complete_vertex_url(custom_api_base=api_base,- vertex_location=litellm_params.pop("vertex_location", None),+ vertex_location=vertex_ai_location,vertex_project=vertex_ai_project,project_id=project_id,partner=VertexPartnerProvider.claude,diff --git a/tests/test_litellm/llms/vertex_ai/vertex_ai_partner_models/anthropic/test_vertex_ai_partner_models_anthropic_messages_config.py b/tests/test_litellm/llms/vertex_ai/vertex_ai_partner_models/anthropic/test_vertex_ai_partner_models_anthropic_messages_config.pynew file mode 100644index 00000000000..ba2e686c5ff--- /dev/null+++ b/tests/test_litellm/llms/vertex_ai/vertex_ai_partner_models/anthropic/test_vertex_ai_partner_models_anthropic_messages_config.py@@ -0,0 +1,33 @@+from unittest.mock import patch++import pytest++from litellm.llms.vertex_ai.vertex_ai_partner_models.anthropic.experimental_pass_through.transformation import (+ VertexAIPartnerModelsAnthropicMessagesConfig,+)+++def test_validate_environment_uses_vertex_ai_location():+ config = VertexAIPartnerModelsAnthropicMessagesConfig()+ headers = {}+ litellm_params = {+ "vertex_ai_project": "test-project",+ "vertex_ai_location": "europe-west1",+ "vertex_credentials": "{}",+ }+ optional_params = {}++ with patch.object(+ config, "_ensure_access_token", return_value=("token", "test-project")+ ), patch.object(+ config, "get_complete_vertex_url", return_value="https://mock-url"+ ) as mock_get_url:+ config.validate_anthropic_messages_environment(+ headers=headers,+ model="claude-3-sonnet",+ messages=[],+ optional_params=optional_params,+ litellm_params=litellm_params,+ api_base=None,+ )+ assert mock_get_url.call_args.kwargs["vertex_location"] == "europe-west1"