diff --git a/litellm/proxy/proxy_server.py b/litellm/proxy/proxy_server.py index 55aee2f408d..649236e78af 100644 --- a/litellm/proxy/proxy_server.py +++ b/litellm/proxy/proxy_server.py @@ -15303,13 +15303,13 @@ _DEPLOYMENT_LITELLM_PARAMS: Final = TypeAdapter(Mapping[str, object]) def _deployment_with_request_drop_params( - deployment: Mapping[str, object] | None, drop_params: object + deployment: Mapping[str, object] | None, sent_params: Mapping[str, object] ) -> Mapping[str, object] | None: - if drop_params is None: + if "drop_params" not in sent_params: return deployment resolved_deployment: Final = deployment or {} litellm_params: Final = _DEPLOYMENT_LITELLM_PARAMS.validate_python(resolved_deployment.get("litellm_params") or {}) - return {**resolved_deployment, "litellm_params": {**litellm_params, "drop_params": drop_params}} + return {**resolved_deployment, "litellm_params": {**litellm_params, "drop_params": sent_params["drop_params"]}} def _counted_request_messages( @@ -16151,7 +16151,7 @@ async def _count_request_tokens( model_to_use = _model sent_params: Final[Mapping[str, object]] = {**_router_default_litellm_params(llm_router), **request_litellm_params} - count_deployment: Final = _deployment_with_request_drop_params(deployment, sent_params.get("drop_params")) + count_deployment: Final = _deployment_with_request_drop_params(deployment, sent_params) conversation_empty: Final = not messages and not contents if prompt and not conversation_empty and not deployment_drops_params(count_deployment): raise ProxyException( diff --git a/tests/unit/proxy/test_proxy_token_counter.py b/tests/unit/proxy/test_proxy_token_counter.py index b419c126455..1bfb0d4cdaf 100644 --- a/tests/unit/proxy/test_proxy_token_counter.py +++ b/tests/unit/proxy/test_proxy_token_counter.py @@ -2191,11 +2191,17 @@ async def test_anthropic_count_tokens_on_a_claude_deployment_sends_the_thinking_ @pytest.mark.asyncio @pytest.mark.parametrize( - ("deployment_drop_params", "request_drop_params"), - ((True, "maybe"), (True, False), (None, " true ")), + ("deployment_drop_params", "request_params"), + ( + (True, {"drop_params": "maybe"}), + (True, {"drop_params": False}), + (True, {"drop_params": None}), + (True, {}), + (None, {"drop_params": " true "}), + ), ) async def test_anthropic_count_tokens_reads_the_request_drop_params_over_the_deployments_like_inference( - monkeypatch: pytest.MonkeyPatch, deployment_drop_params: bool | None, request_drop_params: JsonValue + monkeypatch: pytest.MonkeyPatch, deployment_drop_params: bool | None, request_params: Mapping[str, JsonValue] ) -> None: monkeypatch.setattr(litellm, "disable_aiohttp_transport", True) thinking: Final[dict[str, JsonValue]] = {"type": "enabled", "budget_tokens": 2000, "summary": "auto"} @@ -2206,19 +2212,19 @@ async def test_anthropic_count_tokens_reads_the_request_drop_params_over_the_dep inference_route: Final = respx.post("https://api.anthropic.com/v1/messages").mock( return_value=httpx.Response(200, json=_CLAUDE_MESSAGE_REPLY) ) - await _claude_router("anthropic/claude-opus-4-7", deployment_params).aanthropic_messages( + await _claude_router("anthropic/claude-opus-5-5", deployment_params).aanthropic_messages( model="claude-agent", messages=[{"role": "user", "content": "Weather in SF?"}], max_tokens=4096, thinking=thinking, - drop_params=request_drop_params, + **request_params, ) sent: Final = json.loads(inference_route.calls.last.request.content) response, (count,) = await _count_on_a_claude_deployment( monkeypatch, - "anthropic/claude-opus-4-7", - {"thinking": thinking, "drop_params": request_drop_params}, + "anthropic/claude-opus-5-5", + {"thinking": thinking, **request_params}, lambda _: httpx.Response(200, json={"input_tokens": 7}), deployment_params=deployment_params, )