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]

feat(vertex_ai): let operators drop chosen anthropic-beta values on the Vertex AI pass-through routes (#47185)

Mateo Wang5012083b7210
diff --git a/litellm/proxy/_types.py b/litellm/proxy/_types.py
index 5970ede5c7e..8ff5d1a1002 100644
--- a/litellm/proxy/_types.py
+++ b/litellm/proxy/_types.py
@@ -2774,6 +2774,10 @@ class ConfigGeneralSettings(LiteLLMPydanticObjectBase):
default=None,
description="Serve the OpenAI pass-through WebSocket route, which relays frames to OpenAI under the proxy's own provider credential without reading them. Off by default.",
)
+ vertex_ai_pass_through_drop_anthropic_betas: tuple[str, ...] | None = Field(
+ default=None,
+ description="anthropic-beta header values the Vertex AI pass-through routes (/vertex_ai/* and /vertex-ai/*) remove before calling Vertex, for a beta a Vertex Claude model rejects, whether the client sent them as anthropic-beta or x-pass-anthropic-beta. Every other value the client sent is forwarded unchanged, and the header is left out when no value remains. Unset forwards the header as sent.",
+ )
transcribe_media_buckets: list[str] | None = Field(
default=None,
description="S3 bucket names that keys other than proxy admins may read media from and write transcripts to through the Amazon Transcribe pass-through. Unset means only proxy admins can start transcription jobs.",
diff --git a/litellm/proxy/pass_through_endpoints/llm_passthrough_endpoints.py b/litellm/proxy/pass_through_endpoints/llm_passthrough_endpoints.py
index 3aef5724bdc..f2605a8ec6f 100644
--- a/litellm/proxy/pass_through_endpoints/llm_passthrough_endpoints.py
+++ b/litellm/proxy/pass_through_endpoints/llm_passthrough_endpoints.py
@@ -25,7 +25,7 @@ import httpx
import openai
from fastapi import APIRouter, Depends, HTTPException, Request, Response, WebSocket
from fastapi.responses import StreamingResponse
-from pydantic import ConfigDict, TypeAdapter
+from pydantic import ConfigDict, TypeAdapter, ValidationError
from starlette.websockets import WebSocketState
from typing_extensions import ReadOnly, TypedDict
@@ -44,6 +44,7 @@ from litellm.constants import (
AZURE_SPEECH_STT_DOMAIN,
AZURE_SPEECH_SUBSCRIPTION_KEY_HEADER,
BEDROCK_AGENT_RUNTIME_PASS_THROUGH_ROUTES,
+ PASS_THROUGH_HEADER_PREFIX,
TYPESAFE_DANGER_ZONE_HEADER_PREFIX,
)
from litellm.exceptions import BlockedPiiEntityError, GuardrailRaisedException
@@ -2570,6 +2571,47 @@ def _is_vertex_anthropic_count_tokens_route(endpoint: str) -> bool:
return endpoint.rsplit("/", 1)[-1].split(":", 1)[0] == "count-tokens"
+_VERTEX_DROPPED_ANTHROPIC_BETAS_SETTING: Final = "vertex_ai_pass_through_drop_anthropic_betas"
+_VERTEX_DROPPED_ANTHROPIC_BETAS: Final[TypeAdapter[frozenset[str] | None]] = TypeAdapter(frozenset[str] | None)
+_ANTHROPIC_BETA_REQUEST_HEADERS: Final = ("anthropic-beta", f"{PASS_THROUGH_HEADER_PREFIX}anthropic-beta")
+
+
+def _vertex_dropped_anthropic_betas(
+ general_settings: Mapping[str, object], request_headers: Mapping[str, str]
+) -> frozenset[str]:
+ if not any(name in request_headers for name in _ANTHROPIC_BETA_REQUEST_HEADERS):
+ return frozenset()
+ try:
+ configured: Final = _VERTEX_DROPPED_ANTHROPIC_BETAS.validate_python(
+ general_settings.get(_VERTEX_DROPPED_ANTHROPIC_BETAS_SETTING)
+ )
+ except ValidationError as error:
+ raise HTTPException(
+ status_code=500,
+ detail=f"general_settings.{_VERTEX_DROPPED_ANTHROPIC_BETAS_SETTING} must be a list of strings",
+ ) from error
+ listed_betas: Final = (beta.strip() for beta in ",".join(configured or ()).split(","))
+ return frozenset(beta for beta in listed_betas if beta)
+
+
+def _upstream_vertex_header_value(name: str, value: str, dropped_anthropic_betas: frozenset[str]) -> str | None:
+ if name.lower() != "anthropic-beta":
+ return value
+ betas: Final = tuple(beta.strip() for beta in value.split(","))
+ if dropped_anthropic_betas.isdisjoint(betas):
+ return value
+ return ",".join(beta for beta in betas if beta and beta not in dropped_anthropic_betas) or None
+
+
+def _without_dropped_anthropic_betas(
+ dropped_anthropic_betas: frozenset[str], headers: Mapping[str, str]
+) -> Mapping[str, str]:
+ upstream_values: Final = (
+ (name, _upstream_vertex_header_value(name, value, dropped_anthropic_betas)) for name, value in headers.items()
+ )
+ return MappingProxyType({name: value for name, value in upstream_values if value is not None})
+
+
def _upstream_headers_for_vertex_route(endpoint: str, headers: Mapping[str, str]) -> Mapping[str, str]:
if not _is_vertex_anthropic_count_tokens_route(endpoint):
return headers
@@ -2889,6 +2931,7 @@ async def _base_vertex_proxy_route(
request: Request,
fastapi_response: Response,
get_vertex_pass_through_handler: BaseVertexAIPassThroughHandler,
+ general_settings: Mapping[str, object],
user_api_key_dict: UserAPIKeyAuth | None = None,
router_credentials: LiteLLM_ManagedVectorStore | None = None,
):
@@ -2904,6 +2947,7 @@ async def _base_vertex_proxy_route(
request: FastAPI request object
fastapi_response: FastAPI response object
get_vertex_pass_through_handler: Handler for the specific Vertex AI service
+ general_settings: Proxy general settings, read per request for the anthropic-beta values to drop
user_api_key_dict: User API key authentication dict
router_credentials: Optional vector store credentials from registry (LiteLLM_ManagedVectorStore)
"""
@@ -3022,6 +3066,9 @@ async def _base_vertex_proxy_route(
target=target,
custom_headers=_upstream_headers_for_vertex_route(endpoint, headers),
is_streaming_request=is_streaming_request,
+ upstream_headers_filter=partial(
+ _without_dropped_anthropic_betas, _vertex_dropped_anthropic_betas(general_settings, request.headers)
+ ),
) # dynamically construct pass-through endpoint based on incoming path
try:
@@ -3084,6 +3131,7 @@ async def vertex_discovery_proxy_route(
request=request,
fastapi_response=fastapi_response,
get_vertex_pass_through_handler=discovery_handler,
+ general_settings=_proxy_general_settings(),
router_credentials=vector_store_credentials,
)
@@ -3117,6 +3165,7 @@ async def vertex_proxy_route(
request=request,
fastapi_response=fastapi_response,
get_vertex_pass_through_handler=ai_platform_handler,
+ general_settings=_proxy_general_settings(),
user_api_key_dict=user_api_key_dict,
)
diff --git a/litellm/proxy/pass_through_endpoints/pass_through_endpoints.py b/litellm/proxy/pass_through_endpoints/pass_through_endpoints.py
index b1c448b023b..46b7a724809 100644
--- a/litellm/proxy/pass_through_endpoints/pass_through_endpoints.py
+++ b/litellm/proxy/pass_through_endpoints/pass_through_endpoints.py
@@ -1087,6 +1087,10 @@ from litellm.passthrough.timeout_utils import (
)
+def _unfiltered_headers(headers: Mapping[str, str]) -> Mapping[str, str]:
+ return headers
+
+
async def pass_through_request(
request: Request,
target: str,
@@ -1102,6 +1106,7 @@ async def pass_through_request(
custom_llm_provider: str | None = None,
guardrails_config: dict | None = None,
timeout: float | None = None,
+ upstream_headers_filter: Callable[[Mapping[str, str]], Mapping[str, str]] = _unfiltered_headers,
):
"""
Pass through endpoint handler, makes the httpx request for pass-through endpoints and ensures logging hooks are called
@@ -1122,6 +1127,7 @@ async def pass_through_request(
guardrails_config: Optional field - guardrails configuration for passthrough endpoint
timeout: Optional per-endpoint timeout in seconds. Falls back to
general_settings.pass_through_request_timeout, then 600s.
+ upstream_headers_filter: Optional last rewrite of the headers sent upstream, after x-pass- expansion
"""
from litellm.exceptions import ModifyResponseException
from litellm.litellm_core_utils.litellm_logging import Logging
@@ -1149,13 +1155,15 @@ async def pass_through_request(
#########################################################
try:
url = httpx.URL(target)
- headers = custom_headers
- headers = HttpPassThroughEndpointHelpers.forward_headers_from_request(
+ forwarded_headers: Final = HttpPassThroughEndpointHelpers.forward_headers_from_request(
request_headers=safe_get_request_headers(request).copy(),
- headers=headers,
+ headers=custom_headers,
forward_headers=forward_headers,
)
- upstream_headers: Final = _with_trace_context(headers, parent_span=user_api_key_dict.parent_otel_span)
+ upstream_headers: Final = _with_trace_context(
+ upstream_headers_filter(forwarded_headers),
+ parent_span=user_api_key_dict.parent_otel_span,
+ )
requested_query_params: dict | None = query_params or dict(request.query_params) or None
@@ -2105,6 +2113,7 @@ def create_pass_through_route(
guardrails: dict[str, object] | None = None,
config_file_path: str | None = None,
timeout: float | None = None,
+ upstream_headers_filter: Callable[[Mapping[str, str]], Mapping[str, str]] = _unfiltered_headers,
):
# check if target is an adapter.py or a url
from litellm._uuid import uuid
@@ -2244,6 +2253,7 @@ def create_pass_through_route(
custom_llm_provider=custom_llm_provider,
guardrails_config=cast(dict | None, param_guardrails),
timeout=cast(float | None, param_timeout),
+ upstream_headers_filter=upstream_headers_filter,
)
finally:
if hasattr(request.state, LITELLM_PASS_THROUGH_CUSTOM_BODY_STATE_KEY):
diff --git a/litellm/proxy/proxy_server.py b/litellm/proxy/proxy_server.py
index e3ea9dabe50..69e92948a0e 100644
--- a/litellm/proxy/proxy_server.py
+++ b/litellm/proxy/proxy_server.py
@@ -7048,7 +7048,11 @@ class ProxyConfig:
MappingProxyType(
{
name: typed_general_settings[name]
- for name in ("vector_store_deny_by_default", "search_tool_deny_by_default")
+ for name in (
+ "vector_store_deny_by_default",
+ "search_tool_deny_by_default",
+ "vertex_ai_pass_through_drop_anthropic_betas",
+ )
if name in typed_general_settings
}
)
diff --git a/tests/integration/providers/test_vertex_passthrough_wire.py b/tests/integration/providers/test_vertex_passthrough_wire.py
index 98eb0547d42..148cdff9614 100644
--- a/tests/integration/providers/test_vertex_passthrough_wire.py
+++ b/tests/integration/providers/test_vertex_passthrough_wire.py
@@ -47,6 +47,7 @@ _PROJECT: Final = "scripted-project"
_TOKEN: Final = "scripted-vertex-token"
_CALLER_GOOGLE_TOKEN: Final = "caller-google-token"
_GEMINI_ROUTER_NAME: Final = "vertex-gemini-router"
+_REJECTED_BETA: Final = "files-api-2025-04-14"
_REGIONAL: Final = "us-central1-aiplatform.googleapis.com:443"
_GLOBAL: Final = "aiplatform.googleapis.com:443"
_BYO: Final = "us-east5-aiplatform.googleapis.com:443"
@@ -239,6 +240,10 @@ def rig(tmp_path_factory: pytest.TempPathFactory) -> Iterator[_Rig]:
},
},
]
+ config["general_settings"] = {
+ **config["general_settings"],
+ "vertex_ai_pass_through_drop_anthropic_betas": [_REJECTED_BETA],
+ }
path: Final = directory / "vertex-passthrough.yaml"
path.write_text(yaml.safe_dump(config))
environment: Final = {
@@ -564,3 +569,54 @@ def test_vertex_partner_stream_relays_a_tool_search_turn_verbatim_and_logs_it_on
seconds=70,
)
assert rows[0]["status"] == "success", rows
+
+
[email protected]("alias", ["/vertex_ai", "/vertex-ai"])
+ ("model_path", "caller_headers", "authority"),
+ [
+ pytest.param(
+ f"/v1/projects/{_PROJECT}/locations/global/publishers/anthropic/models/claude-sonnet-4-5",
+ {},
+ _GLOBAL,
+ id="use_in_pass_through",
+ ),
+ pytest.param(
+ "/v1/projects/byo-project/locations/us-east5/publishers/anthropic/models/claude-byo",
+ {"x-goog-api-key": _CALLER_GOOGLE_TOKEN},
+ _BYO,
+ id="caller-credentials",
+ ),
+ ],
+)
+def test_vertex_partner_call_drops_the_configured_anthropic_beta_and_forwards_the_rest_in_order(
+ rig: _Rig, alias: str, model_path: str, caller_headers: dict[str, str], authority: str
+) -> None:
+ body: Final[dict[str, JsonValue]] = {
+ "anthropic_version": "vertex-2023-10-16",
+ "max_tokens": 64,
+ "messages": [{"role": "user", "content": "hi"}],
+ }
+ with rig.proxy.scenario() as scenario:
+ key: Final = scenario.key()
+ response: Final = rig.proxy.client.post(
+ f"{alias}{model_path}:rawPredict",
+ json=body,
+ headers={
+ "Authorization": f"Bearer {key}",
+ "anthropic-beta": f"interleaved-thinking-2025-05-14, {_REJECTED_BETA} ,effort-2025-11-24",
+ **caller_headers,
+ },
+ )
+ assert response.status_code == 200, response.text
+ assert response.json() == _CLAUDE_REPLY, response.text
+ received: Final = rig.vertex.drain()
+ assert [(request.method, request.target) for request in received] == [("POST", f"{model_path}:rawPredict")], (
+ received
+ )
+ assert rig.tunnel.drain() == [authority]
+ upstream: Final = received[0]
+ assert upstream.headers["anthropic-beta"] == "interleaved-thinking-2025-05-14,effort-2025-11-24", (
+ upstream.headers
+ )
+ assert _JSON_OBJECT.validate_json(upstream.body) == body, upstream.body
diff --git a/tests/unit/proxy/pass_through_endpoints/test_llm_pass_through_endpoints.py b/tests/unit/proxy/pass_through_endpoints/test_llm_pass_through_endpoints.py
index ed89cc37544..4dbe1f2ef8d 100644
--- a/tests/unit/proxy/pass_through_endpoints/test_llm_pass_through_endpoints.py
+++ b/tests/unit/proxy/pass_through_endpoints/test_llm_pass_through_endpoints.py
@@ -370,6 +370,7 @@ class TestVertexAIPassThroughHandler:
target=f"https://{test_location}-aiplatform.googleapis.com/v1/projects/{test_project}/locations/{test_location}/publishers/google/models/gemini-1.5-flash:generateContent",
custom_headers={"Authorization": f"Bearer {test_token}"},
is_streaming_request=False,
+ upstream_headers_filter=mock.ANY,
)
@pytest.mark.asyncio
@@ -469,6 +470,7 @@ class TestVertexAIPassThroughHandler:
target=f"https://aiplatform.googleapis.com/v1/projects/{test_project}/locations/{test_location}/publishers/google/models/gemini-1.5-flash:generateContent",
custom_headers={"Authorization": f"Bearer {test_token}"},
is_streaming_request=False,
+ upstream_headers_filter=mock.ANY,
)
@pytest.mark.parametrize(
@@ -564,6 +566,7 @@ class TestVertexAIPassThroughHandler:
target=f"https://{default_location}-aiplatform.googleapis.com/v1/projects/{default_project}/locations/{default_location}/publishers/google/models/gemini-1.5-flash:generateContent",
custom_headers={"Authorization": f"Bearer {default_credentials}"},
is_streaming_request=False,
+ upstream_headers_filter=mock.ANY,
)
@pytest.mark.asyncio
diff --git a/tests/unit/proxy/pass_through_endpoints/test_llm_passthrough_endpoints.py b/tests/unit/proxy/pass_through_endpoints/test_llm_passthrough_endpoints.py
index 98ea2269252..e658556bd1f 100644
--- a/tests/unit/proxy/pass_through_endpoints/test_llm_passthrough_endpoints.py
+++ b/tests/unit/proxy/pass_through_endpoints/test_llm_passthrough_endpoints.py
@@ -1,10 +1,16 @@
import asyncio
import importlib
import json
+from collections.abc import Iterator
from typing import Final
+import httpx
import pytest
+import responses
import respx
+from cryptography.hazmat.primitives import serialization
+from cryptography.hazmat.primitives.asymmetric import rsa
+from fastapi.testclient import TestClient
import litellm
from litellm import Router
@@ -257,3 +263,259 @@ async def test_gemini_pass_through_endpoint_forwards_key_and_body(
assert outbound.url.path == f"/{endpoint}"
assert outbound.url.params["key"] == "gemini-test-key"
assert json.loads(outbound.content) == json.loads(body)
+
+
+_VERTEX_DEPLOYMENT_PATH: Final = (
+ "v1/projects/deployment-project/locations/global/publishers/anthropic/models/claude-sonnet-4-5:rawPredict"
+)
+_VERTEX_CALLER_PATH: Final = (
+ "v1/projects/caller-project/locations/global/publishers/anthropic/models/claude-haiku-4-5:rawPredict"
+)
+_VERTEX_DEPLOYMENT_PROJECT: Final = "deployment-project"
+_VERTEX_TOKEN_URI: Final = "https://oauth2.googleapis.com/token"
+_VERTEX_MINTED_TOKEN: Final = "minted-vertex-token"
+_VERTEX_CALLER_GOOGLE_TOKEN: Final = "caller-google-token"
+_VERTEX_REJECTED_BETA: Final = "files-api-2025-04-14"
+_VERTEX_SENT_BETAS: Final = f"claude-code-20250219, {_VERTEX_REJECTED_BETA} ,effort-2025-11-24"
+_VERTEX_CLAUDE_BODY: Final = {
+ "anthropic_version": "vertex-2023-10-16",
+ "max_tokens": 8,
+ "messages": [{"role": "user", "content": "hi"}],
+}
+_VERTEX_CLAUDE_REPLY: Final = {"id": "msg_vertex", "type": "message", "content": []}
+
+
+ ("header_name", "sent", "dropped", "expected"),
+ [
+ pytest.param(
+ "anthropic-beta",
+ "claude-code-20250219,files-api-2025-04-14,effort-2025-11-24",
+ {"files-api-2025-04-14"},
+ "claude-code-20250219,effort-2025-11-24",
+ id="drops-one-keeps-order",
+ ),
+ pytest.param(
+ "anthropic-beta",
+ " claude-code-20250219 , files-api-2025-04-14 ,effort-2025-11-24 ",
+ {"files-api-2025-04-14"},
+ "claude-code-20250219,effort-2025-11-24",
+ id="whitespace-around-values",
+ ),
+ pytest.param(
+ "Anthropic-Beta",
+ "effort-2025-11-24,files-api-2025-04-14",
+ {"files-api-2025-04-14"},
+ "effort-2025-11-24",
+ id="header-name-any-case",
+ ),
+ pytest.param(
+ "anthropic-beta",
+ "files-api-2025-04-14, skills-2025-10-02",
+ {"files-api-2025-04-14", "skills-2025-10-02"},
+ None,
+ id="all-dropped-removes-header",
+ ),
+ pytest.param(
+ "anthropic-beta",
+ " claude-code-20250219 ,files-api-2025-04-14",
+ set(),
+ " claude-code-20250219 ,files-api-2025-04-14",
+ id="no-setting-byte-identical",
+ ),
+ pytest.param(
+ "anthropic-beta",
+ " claude-code-20250219 ,files-api-2025-04-14-preview",
+ {"files-api-2025-04-14"},
+ " claude-code-20250219 ,files-api-2025-04-14-preview",
+ id="exact-match-only",
+ ),
+ ],
+)
+def test_vertex_upstream_headers_drop_only_the_configured_anthropic_betas(
+ header_name: str, sent: str, dropped: set[str], expected: str | None
+) -> None:
+ from litellm.proxy.pass_through_endpoints.llm_passthrough_endpoints import (
+ _without_dropped_anthropic_betas,
+ )
+
+ other_headers: Final = {"content-type": "application/json", "Authorization": "Bearer vertex-access-token"}
+
+ upstream: Final = _without_dropped_anthropic_betas(frozenset(dropped), {header_name: sent, **other_headers})
+
+ expected_beta: Final = {} if expected is None else {header_name: expected}
+ assert dict(upstream) == {**expected_beta, **other_headers}
+
+
+def _vertex_service_account_json() -> str:
+ private_key: Final = (
+ rsa.generate_private_key(public_exponent=65537, key_size=2048)
+ .private_bytes(serialization.Encoding.PEM, serialization.PrivateFormat.PKCS8, serialization.NoEncryption())
+ .decode()
+ )
+ return json.dumps(
+ {
+ "type": "service_account",
+ "project_id": _VERTEX_DEPLOYMENT_PROJECT,
+ "private_key_id": "test",
+ "private_key": private_key,
+ "client_email": f"test@{_VERTEX_DEPLOYMENT_PROJECT}.iam.gserviceaccount.com",
+ "client_id": "0",
+ "token_uri": _VERTEX_TOKEN_URI,
+ }
+ )
+
+
+def vertex_proxy(
+ monkeypatch: pytest.MonkeyPatch, httpx_transport: None, isolate_passthrough_endpoint_router_state: None
+) -> Iterator[TestClient]:
+ from litellm.proxy import proxy_server
+
+ router: Final = Router(
+ model_list=[
+ {
+ "model_name": "claude-sonnet-4-5",
+ "litellm_params": {
+ "model": "vertex_ai/claude-sonnet-4-5",
+ "vertex_project": _VERTEX_DEPLOYMENT_PROJECT,
+ "vertex_location": "global",
+ "vertex_credentials": _vertex_service_account_json(),
+ "use_in_pass_through": True,
+ },
+ }
+ ]
+ )
+ monkeypatch.setattr(proxy_server, "llm_router", router)
+ with responses.RequestsMock(assert_all_requests_are_fired=False) as google_oauth:
+ google_oauth.post(
+ _VERTEX_TOKEN_URI,
+ json={"access_token": _VERTEX_MINTED_TOKEN, "expires_in": 3600, "token_type": "Bearer"},
+ )
+ yield TestClient(proxy_server.app)
+
+
[email protected]("beta_header", ["anthropic-beta", "x-pass-anthropic-beta"])
[email protected]("alias", ["/vertex_ai", "/vertex-ai"])
+ ("model_path", "caller_headers", "upstream_authorization"),
+ [
+ pytest.param(
+ _VERTEX_DEPLOYMENT_PATH,
+ {},
+ f"Bearer {_VERTEX_MINTED_TOKEN}",
+ id="use_in_pass_through-deployment",
+ ),
+ pytest.param(
+ _VERTEX_CALLER_PATH,
+ {"Authorization": f"Bearer {_VERTEX_CALLER_GOOGLE_TOKEN}"},
+ f"Bearer {_VERTEX_CALLER_GOOGLE_TOKEN}",
+ id="caller-credentials",
+ ),
+ ],
+)
+def test_vertex_pass_through_drops_the_configured_anthropic_beta_before_calling_vertex(
+ vertex_proxy: TestClient,
+ respx_mock: "respx.MockRouter",
+ monkeypatch: pytest.MonkeyPatch,
+ beta_header: str,
+ alias: str,
+ model_path: str,
+ caller_headers: dict[str, str],
+ upstream_authorization: str,
+) -> None:
+ from litellm.proxy import proxy_server
+
+ monkeypatch.setitem(
+ proxy_server.general_settings, "vertex_ai_pass_through_drop_anthropic_betas", [_VERTEX_REJECTED_BETA]
+ )
+ upstream: Final = respx_mock.post(f"https://aiplatform.googleapis.com/{model_path}").mock(
+ return_value=httpx.Response(200, json=_VERTEX_CLAUDE_REPLY)
+ )
+
+ response: Final = vertex_proxy.post(
+ f"{alias}/{model_path}",
+ json=_VERTEX_CLAUDE_BODY,
+ headers={"x-litellm-api-key": "sk-caller", beta_header: _VERTEX_SENT_BETAS, **caller_headers},
+ )
+
+ assert (response.status_code, response.json()) == (200, _VERTEX_CLAUDE_REPLY)
+ outbound: Final = upstream.calls.last.request
+ assert outbound.headers["anthropic-beta"] == "claude-code-20250219,effort-2025-11-24"
+ assert outbound.headers["authorization"] == upstream_authorization
+ assert json.loads(outbound.content) == _VERTEX_CLAUDE_BODY
+
+
+
+ "configured",
+ [[f" {_VERTEX_REJECTED_BETA} "], [f"{_VERTEX_REJECTED_BETA},afk-mode-2026-01-31"]],
+ ids=["spaces-around-the-entry", "comma-separated-entry"],
+)
+def test_vertex_pass_through_matches_a_configured_beta_written_the_way_the_header_is(
+ vertex_proxy: TestClient, respx_mock: "respx.MockRouter", monkeypatch: pytest.MonkeyPatch, configured: list[str]
+) -> None:
+ from litellm.proxy import proxy_server
+
+ monkeypatch.setitem(proxy_server.general_settings, "vertex_ai_pass_through_drop_anthropic_betas", configured)
+ upstream: Final = respx_mock.post(f"https://aiplatform.googleapis.com/{_VERTEX_CALLER_PATH}").mock(
+ return_value=httpx.Response(200, json=_VERTEX_CLAUDE_REPLY)
+ )
+
+ response: Final = vertex_proxy.post(
+ f"/vertex_ai/{_VERTEX_CALLER_PATH}",
+ json=_VERTEX_CLAUDE_BODY,
+ headers={
+ "x-litellm-api-key": "sk-caller",
+ "Authorization": f"Bearer {_VERTEX_CALLER_GOOGLE_TOKEN}",
+ "anthropic-beta": _VERTEX_SENT_BETAS,
+ },
+ )
+
+ assert (response.status_code, response.json()) == (200, _VERTEX_CLAUDE_REPLY)
+ assert upstream.calls.last.request.headers["anthropic-beta"] == "claude-code-20250219,effort-2025-11-24"
+
+def test_vertex_pass_through_refuses_a_malformed_drop_setting_without_calling_vertex(
+ vertex_proxy: TestClient, respx_mock: "respx.MockRouter", monkeypatch: pytest.MonkeyPatch
+) -> None:
+ from litellm.proxy import proxy_server
+
+ monkeypatch.setitem(
+ proxy_server.general_settings, "vertex_ai_pass_through_drop_anthropic_betas", _VERTEX_REJECTED_BETA
+ )
+
+ response: Final = vertex_proxy.post(
+ f"/vertex_ai/{_VERTEX_CALLER_PATH}",
+ json=_VERTEX_CLAUDE_BODY,
+ headers={
+ "x-litellm-api-key": "sk-caller",
+ "Authorization": f"Bearer {_VERTEX_CALLER_GOOGLE_TOKEN}",
+ "anthropic-beta": _VERTEX_SENT_BETAS,
+ },
+ )
+
+ assert response.status_code == 500
+ assert "vertex_ai_pass_through_drop_anthropic_betas must be a list of strings" in response.text
+ assert respx_mock.calls.call_count == 0
+
+
+def test_vertex_pass_through_forwards_a_request_without_betas_despite_a_malformed_drop_setting(
+ vertex_proxy: TestClient, respx_mock: "respx.MockRouter", monkeypatch: pytest.MonkeyPatch
+) -> None:
+ from litellm.proxy import proxy_server
+
+ monkeypatch.setitem(
+ proxy_server.general_settings, "vertex_ai_pass_through_drop_anthropic_betas", _VERTEX_REJECTED_BETA
+ )
+ upstream: Final = respx_mock.post(f"https://aiplatform.googleapis.com/{_VERTEX_CALLER_PATH}").mock(
+ return_value=httpx.Response(200, json=_VERTEX_CLAUDE_REPLY)
+ )
+
+ response: Final = vertex_proxy.post(
+ f"/vertex_ai/{_VERTEX_CALLER_PATH}",
+ json=_VERTEX_CLAUDE_BODY,
+ headers={"x-litellm-api-key": "sk-caller", "Authorization": f"Bearer {_VERTEX_CALLER_GOOGLE_TOKEN}"},
+ )
+
+ assert (response.status_code, response.json()) == (200, _VERTEX_CLAUDE_REPLY)
+ assert "anthropic-beta" not in upstream.calls.last.request.headers
diff --git a/tests/unit/proxy/pass_through_endpoints/test_vertex_passthrough_load_balancing.py b/tests/unit/proxy/pass_through_endpoints/test_vertex_passthrough_load_balancing.py
index 2922790ea37..ed14eeda6a2 100644
--- a/tests/unit/proxy/pass_through_endpoints/test_vertex_passthrough_load_balancing.py
+++ b/tests/unit/proxy/pass_through_endpoints/test_vertex_passthrough_load_balancing.py
@@ -91,6 +91,7 @@ async def test_vertex_passthrough_load_balancing():
request=mock_request,
fastapi_response=mock_response,
get_vertex_pass_through_handler=mock_handler,
+ general_settings={},
)
# Verify
@@ -404,6 +405,7 @@ async def test_vertex_passthrough_drops_anthropic_beta_only_on_count_tokens(
request=MagicMock(),
fastapi_response=MagicMock(),
get_vertex_pass_through_handler=VertexAIPassThroughHandler(),
+ general_settings={},
)
upstream_headers = mock_create_route.call_args.kwargs["custom_headers"]
@@ -747,6 +749,7 @@ async def test_vertex_passthrough_custom_model_name_replaced_in_url():
request=mock_request,
fastapi_response=mock_response,
get_vertex_pass_through_handler=mock_handler,
+ general_settings={},
)
# Verify the router was called with the custom model name (extracted from URL)
@@ -836,6 +839,7 @@ async def test_vertex_passthrough_attributes_the_call_to_the_resolved_deployment
request=mock_request,
fastapi_response=MagicMock(),
get_vertex_pass_through_handler=mock_handler,
+ general_settings={},
)
assert logging_kwargs["litellm_params"]["metadata"]["model_info"]["id"] == "vertex-gemini-38-flash-dep"
diff --git a/tests/unit/proxy/proxy_server/test_proxy_config.py b/tests/unit/proxy/proxy_server/test_proxy_config.py
index 8837fa095e8..e59dd19271c 100644
--- a/tests/unit/proxy/proxy_server/test_proxy_config.py
+++ b/tests/unit/proxy/proxy_server/test_proxy_config.py
@@ -2579,6 +2579,26 @@ async def test_load_config_rejects_non_boolean_deny_by_default(
await ProxyConfig().load_config(router=None, config_file_path=str(config_file))
+
+ "yaml_value", ["files-api-2025-04-14", "[files-api-2025-04-14, 7]"], ids=["bare-string", "non-string-entry"]
+)
+async def test_load_config_rejects_a_malformed_vertex_drop_anthropic_betas_list(
+ tmp_path: Path, monkeypatch: pytest.MonkeyPatch, yaml_value: str
+):
+ config_file: Final = tmp_path / "vertex_drop_betas.yaml"
+ config_file.write_text(
+ "model_list: []\nlitellm_settings: {}\ngeneral_settings:\n"
+ f" vertex_ai_pass_through_drop_anthropic_betas: {yaml_value}\n"
+ )
+ monkeypatch.setattr("litellm.proxy.proxy_server.prisma_client", None)
+ monkeypatch.setattr("litellm.proxy.proxy_server.store_model_in_db", False)
+ monkeypatch.delenv("LITELLM_CONFIG_BUCKET_NAME", raising=False)
+
+ with pytest.raises(ValidationError, match="vertex_ai_pass_through_drop_anthropic_betas"):
+ await ProxyConfig().load_config(router=None, config_file_path=str(config_file))
+
@pytest.mark.asyncio
async def test_ProxyConfig_load_config_resolves_router_settings_plugins(tmp_path, monkeypatch):
"""Regression: router_settings.plugins dotted-path strings must be resolved to
diff --git a/tests/unit/proxy/vector_store_endpoints/test_vector_store_tenant_guard.py b/tests/unit/proxy/vector_store_endpoints/test_vector_store_tenant_guard.py
index 981fbfcf3e5..29efc41b484 100644
--- a/tests/unit/proxy/vector_store_endpoints/test_vector_store_tenant_guard.py
+++ b/tests/unit/proxy/vector_store_endpoints/test_vector_store_tenant_guard.py
@@ -451,6 +451,7 @@ async def test_vertex_discovery_denies_other_team_vector_store_credentials():
request=request,
fastapi_response=Response(),
get_vertex_pass_through_handler=MagicMock(),
+ general_settings={},
router_credentials=vector_store_credentials,
)
diff --git a/ui/litellm-dashboard/src/lib/http/schema.d.ts b/ui/litellm-dashboard/src/lib/http/schema.d.ts
index c33ef86af72..a111ed1d773 100644
--- a/ui/litellm-dashboard/src/lib/http/schema.d.ts
+++ b/ui/litellm-dashboard/src/lib/http/schema.d.ts
@@ -30279,6 +30279,11 @@ export interface components {
* @default false
*/
vector_store_deny_by_default: boolean;
+ /**
+ * Vertex Ai Pass Through Drop Anthropic Betas
+ * @description anthropic-beta header values the Vertex AI pass-through routes (/vertex_ai/* and /vertex-ai/*) remove before calling Vertex, for a beta a Vertex Claude model rejects, whether the client sent them as anthropic-beta or x-pass-anthropic-beta. Every other value the client sent is forwarded unchanged, and the header is left out when no value remains. Unset forwards the header as sent.
+ */
+ vertex_ai_pass_through_drop_anthropic_betas?: string[] | null;
};
/** ConfigList */
ConfigList: {