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(anthropic_messages): price native /v1/messages vertex calls on the deployment location
mateo-berri7b6f537855bf
diff --git a/litellm/llms/custom_httpx/llm_http_handler.py b/litellm/llms/custom_httpx/llm_http_handler.pyindex 3ee803646a9..e03942100b0 100644--- a/litellm/llms/custom_httpx/llm_http_handler.py+++ b/litellm/llms/custom_httpx/llm_http_handler.py@@ -5,7 +5,7 @@ import sslfrom collections.abc import AsyncIterator, Coroutine, Iterator, Mapping, Sequencefrom contextlib import asynccontextmanagerfrom functools import lru_cache-from types import ModuleType+from types import MappingProxyType, ModuleTypefrom typing import TYPE_CHECKING, Any, Final, Literal, Optional, TypedDict, TypeVar, Union, cast, get_type_hintsfrom urllib.parse import parse_qs, urlencode, urlparse, urlunparse@@ -2069,6 +2069,14 @@ class BaseLLMHTTPHandler:if anthropic_messages_provider_config.should_filter_anthropic_beta_headers():headers = update_headers_with_filtered_beta(headers=headers, provider=custom_llm_provider)+ from litellm.llms.vertex_ai.vertex_llm_base import VertexBase++ explicit_vertex_location: Final = VertexBase.explicit_vertex_ai_location(MappingProxyType(dict(litellm_params)))+ vertex_location_params: Final = (+ MappingProxyType({"vertex_location": explicit_vertex_location})+ if explicit_vertex_location+ else MappingProxyType({})+ )logging_obj.update_from_kwargs(kwargs=kwargs,model=model,@@ -2077,6 +2085,7 @@ class BaseLLMHTTPHandler:"preset_cache_key": None,"stream_response": {},"model_info": kwargs.get("model_info"),+ **vertex_location_params,**anthropic_messages_optional_request_params,},custom_llm_provider=custom_llm_provider,diff --git a/tests/test_litellm/llms/custom_httpx/test_llm_http_handler.py b/tests/test_litellm/llms/custom_httpx/test_llm_http_handler.pyindex 69f2312f203..9e9242137e6 100644--- a/tests/test_litellm/llms/custom_httpx/test_llm_http_handler.py+++ b/tests/test_litellm/llms/custom_httpx/test_llm_http_handler.py@@ -2226,3 +2226,78 @@ def test_direct_vector_store_search_debug_log_omits_stored_credentials(caplog, ilogged = "\n".join(record.getMessage() for record in caplog.records)assert "sup3r-s3cret-valkey-pw" not in loggedassert "sk-embedding-s3cret" not in logged+++async def test_async_anthropic_messages_handler_carries_deployment_vertex_location_for_pricing(monkeypatch):+ """+ The proxy pre-creates the logging object before the router picks a deployment, so the+ native /v1/messages path must copy the deployment's vertex_location into the logging+ params it updates; otherwise cost resolution falls back to the environment and every+ call on this surface prices with the regional uplift (#34393).+ """+ import contextlib+ from datetime import datetime++ from litellm.litellm_core_utils.litellm_logging import (+ Logging,+ _resolve_vertex_location_for_cost,+ )++ monkeypatch.setenv("VERTEXAI_LOCATION", "us-east5")+ monkeypatch.setattr(litellm, "vertex_location", None)++ handler = BaseLLMHTTPHandler()++ async def logging_obj_after_handler(generic_params):+ logging_obj = Logging(+ model="vertex_ai/claude-haiku-4-5@20251001",+ messages=[{"role": "user", "content": "hi"}],+ stream=False,+ call_type="anthropic_messages",+ start_time=datetime.now(),+ litellm_call_id="vertex-messages-location",+ function_id="f",+ )+ logging_obj.update_environment_variables(+ model="vertex_ai/claude-haiku-4-5@20251001",+ user="",+ optional_params={},+ litellm_params={"api_base": ""},+ custom_llm_provider="vertex_ai",+ )+ mock_config = Mock()+ mock_config.validate_anthropic_messages_environment = Mock(+ return_value=({"authorization": "Bearer t"}, "https://us-east5-aiplatform.googleapis.com")+ )+ mock_config.transform_anthropic_messages_request = Mock(+ return_value={"model": "claude-haiku-4-5@20251001", "messages": []}+ )+ with contextlib.suppress(Exception):+ await handler.async_anthropic_messages_handler(+ model="claude-haiku-4-5@20251001",+ messages=[{"role": "user", "content": "hi"}],+ anthropic_messages_provider_config=mock_config,+ anthropic_messages_optional_request_params={"max_tokens": 10},+ custom_llm_provider="vertex_ai",+ litellm_params=generic_params,+ logging_obj=logging_obj,+ client=AsyncMock(),+ kwargs={},+ )+ return logging_obj++ global_deployment = await logging_obj_after_handler(GenericLiteLLMParams(vertex_location="global"))+ assert global_deployment.litellm_params["vertex_location"] == "global"+ assert (+ _resolve_vertex_location_for_cost(+ custom_llm_provider="vertex_ai",+ litellm_params=global_deployment.litellm_params,+ optional_params=global_deployment.optional_params,+ model="claude-haiku-4-5@20251001",+ )+ == "global"+ )++ unconfigured_deployment = await logging_obj_after_handler(GenericLiteLLMParams())+ assert "vertex_location" not in unconfigured_deployment.litellm_paramsdiff --git a/tests/test_litellm/test_utils.py b/tests/test_litellm/test_utils.pyindex 1d9477432ee..60453931595 100644--- a/tests/test_litellm/test_utils.py+++ b/tests/test_litellm/test_utils.py@@ -832,6 +832,7 @@ def test_aaamodel_prices_and_context_window_json_is_valid():"output_cost_per_token_above_200k_tokens_priority": {"type": "number"},"output_cost_per_token_above_272k_tokens_priority": {"type": "number"},"output_cost_per_token_above_272k_tokens_flex": {"type": "number"},+ "regional_endpoint_uplift_multiplier": {"type": "number"},"regional_processing_uplift_multiplier_eu": {"type": "number"},"regional_processing_uplift_multiplier_us": {"type": "number"},"input_cost_per_pixel": {"type": "number"},