From a207c3a2fe1d1335f0714634afc9380b459f0f35 Mon Sep 17 00:00:00 2001 From: moe-berri Date: Mon, 26 Oct 2026 15:31:01 -0700 Subject: [PATCH] refactor: keep forwarded credential isolation opt-in by provider --- litellm/router.py | 3 +- tests/unit/test_router/test_router.py | 46 --------------------------- 2 files changed, 2 insertions(+), 47 deletions(-) diff --git a/litellm/router.py b/litellm/router.py index acabb5f41c3..bde5fb8a27e 100644 --- a/litellm/router.py +++ b/litellm/router.py @@ -563,6 +563,7 @@ _ALIAS_PARAMS_NEVER_FORWARDED: Final = frozenset( {"model", "api_base", "api_key", "api_version", "responses_api_version"} ) _ALIAS_MARKER_FORWARDED_PARAMS_KWARG: Final = "_alias_marker_forwarded_params" +_FORWARDED_CREDENTIAL_ISOLATION_PROVIDERS: Final = frozenset({"chatgpt"}) _CLAUDE_CODE_SESSION_ID_RE: Final = re.compile(r"^[a-zA-Z0-9_\-]{8,}$") _CLAUDE_CODE_SESSION_ROUTER_TTL_SECONDS: Final = 3600 CLAUDE_CODE_SESSION_ROUTER_BINDING_TARGET: Final = "claude_code_session_router_binding" @@ -4822,7 +4823,7 @@ class Router: ProviderSpecificHeaderUtils.forwarded_authorization( request_context.get("provider_specific_header"), deployment_provider ) - if deployment_provider == "chatgpt" + if deployment_provider in _FORWARDED_CREDENTIAL_ISOLATION_PROVIDERS else None ) if is_clientside_credential(request_kwargs=kwargs) or forwarded_authorization is not None: diff --git a/tests/unit/test_router/test_router.py b/tests/unit/test_router/test_router.py index 28fffb29a1a..70376fc4069 100644 --- a/tests/unit/test_router/test_router.py +++ b/tests/unit/test_router/test_router.py @@ -27,7 +27,6 @@ from pydantic import BaseModel, TypeAdapter import litellm from litellm import APIConnectionError, Router -from litellm.llms.custom_httpx.http_handler import AsyncHTTPHandler from litellm._logging import verbose_logger, verbose_router_logger from litellm.caching import RedisCache, RedisClusterCache from litellm.caching.caching import DualCache @@ -30159,48 +30158,3 @@ def test_request_carries_image_sees_chat_parts_and_responses_input_items(): assert litellm.Router._request_carries_image(None, {"input": _IMAGE_RESPONSES_INPUT}) is True assert litellm.Router._request_carries_image([{"role": "user", "content": "Say hi"}], {}) is False assert litellm.Router._request_carries_image(None, {"input": "Say hi"}) is False - - -@pytest.mark.asyncio -async def test_anthropic_forwarded_oauth_preserves_configured_deployment( - respx_mock: respx.MockRouter, -) -> None: - route: Final = respx_mock.post("https://api.anthropic.com/v1/messages").respond( - 200, - json={ - "id": "msg-oauth", - "type": "message", - "role": "assistant", - "model": "claude-sonnet-5-5", - "content": [{"type": "text", "text": "subscription reply"}], - "stop_reason": "end_turn", - "stop_sequence": None, - "usage": {"input_tokens": 2, "output_tokens": 2}, - }, - ) - router: Final = Router( - model_list=[{ - "model_name": "subscription", - "litellm_params": {"model": "anthropic/claude-sonnet-5-5", "api_key": "fake-saved-key"}, - "model_info": {"id": "configured-anthropic-deployment"}, - }], - num_retries=0, - ) - client: Final = AsyncHTTPHandler(transport=httpx.AsyncHTTPTransport()) - try: - for token in ("sk-ant-oat-fake-client-a", "sk-ant-oat-fake-client-b"): - response: Final = await router.acompletion( - model="subscription", - messages=[{"role": "user", "content": "hello"}], - client=client, - provider_specific_header={ - "custom_llm_provider": "anthropic", - "extra_headers": {"authorization": f"Bearer {token}"}, - }, - ) - assert response.choices[0].message.content == "subscription reply" - assert response._hidden_params["model_id"] == "configured-anthropic-deployment" - assert route.calls[-1].request.headers["authorization"] == f"Bearer {token}" - assert "x-api-key" not in route.calls[-1].request.headers - finally: - await client.close()