mirror of
https://github.com/BerriAI/litellm.git
synced 2026-11-18 09:45:23 +00:00
refactor: keep forwarded credential isolation opt-in by provider
This commit is contained in:
parent
daf8751cea
commit
a207c3a2fe
2 changed files with 2 additions and 47 deletions
|
|
@ -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:
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue