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(responses): honor nested additional_drop_params paths
Devin AI0cd14b83b33d
diff --git a/litellm/responses/utils.py b/litellm/responses/utils.pyindex 599e978df6a..677c4950f96 100644--- a/litellm/responses/utils.py+++ b/litellm/responses/utils.py@@ -1,6 +1,7 @@import base64import refrom collections.abc import Iterable, Mapping, Sequence+from functools import reducefrom typing import Any, Final, Optional, TypeVar, Union, cast, get_type_hints, overloadfrom pydantic import BaseModel@@ -8,6 +9,7 @@ from typing_extensions import TypeIs # noqa: TID251 # narrows untyped wire payimport litellmfrom litellm._logging import verbose_logger+from litellm.litellm_core_utils.dot_notation_indexing import delete_nested_value, is_nested_pathfrom litellm.llms.base_llm.responses.transformation import BaseResponsesAPIConfigfrom litellm.types.llms.openai import (AllMessageValues,@@ -29,6 +31,11 @@ from litellm.types.utils import ()+def _apply_nested_drop_params(params: dict[str, Any], additional_drop_params: list[str] | None) -> dict[str, Any]:+ nested_paths: Final = tuple(path for path in additional_drop_params or () if is_nested_path(path))+ return reduce(lambda acc, path: delete_nested_value(acc, path), nested_paths, params)++def _output_token_detail(details: object, field: str) -> int | None:value: Final = getattr(details, field, None)return value if isinstance(value, int) else None@@ -265,13 +272,16 @@ class ResponsesAPIRequestUtils:special_params: Final[dict[str, object]] = params.pop("kwargs", {})additional_drop_params: Final[list[str] | None] = params.pop("additional_drop_params", None)- non_default_params: Final = PreProcessNonDefaultParams.base_pre_process_non_default_params(- passed_params=params,- special_params=special_params,- custom_llm_provider=custom_llm_provider,- additional_drop_params=additional_drop_params,- default_param_values={k: None for k in valid_keys},- additional_endpoint_specific_params=["input"],+ non_default_params: Final = _apply_nested_drop_params(+ PreProcessNonDefaultParams.base_pre_process_non_default_params(+ passed_params=params,+ special_params=special_params,+ custom_llm_provider=custom_llm_provider,+ additional_drop_params=additional_drop_params,+ default_param_values={k: None for k in valid_keys},+ additional_endpoint_specific_params=["input"],+ ),+ additional_drop_params,)# decode previous_response_id if it's a litellm encoded iddiff --git a/tests/test_litellm/responses/test_responses_utils.py b/tests/test_litellm/responses/test_responses_utils.pyindex 9d9eefdceb3..f1d197c1c22 100644--- a/tests/test_litellm/responses/test_responses_utils.py+++ b/tests/test_litellm/responses/test_responses_utils.py@@ -119,6 +119,63 @@ class TestResponsesAPIRequestUtils:assert result["max_output_tokens"] == 100assert result["prompt"] == {"id": "pmpt_456"}+ def test_get_requested_response_api_optional_param_drops_nested_path(self):+ """Nested additional_drop_params paths like reasoning.summary must be honored"""+ params = {+ "temperature": 0.1,+ "reasoning": {"effort": "high", "summary": "auto"},+ "additional_drop_params": ["reasoning.summary"],+ }++ result = ResponsesAPIRequestUtils.get_requested_response_api_optional_param(params)++ assert result["reasoning"] == {"effort": "high"}+ assert result["temperature"] == 0.1++ def test_get_requested_response_api_optional_param_drops_array_path(self):+ """Array wildcard paths like tools[*].input_examples must be honored"""+ params = {+ "tools": [{"type": "function", "name": "t", "input_examples": ["x"]}],+ "additional_drop_params": ["tools[*].input_examples"],+ }++ result = ResponsesAPIRequestUtils.get_requested_response_api_optional_param(params)++ assert result["tools"] == [{"type": "function", "name": "t"}]++ def test_get_requested_response_api_optional_param_drops_top_level(self):+ """Top-level additional_drop_params keys must still be honored"""+ params = {+ "reasoning": {"effort": "high", "summary": "auto"},+ "additional_drop_params": ["reasoning"],+ }++ result = ResponsesAPIRequestUtils.get_requested_response_api_optional_param(params)++ assert "reasoning" not in result++ def test_get_requested_response_api_optional_param_non_matching_nested_path(self):+ """A nested path that does not match anything leaves params untouched"""+ params = {+ "reasoning": {"effort": "high", "summary": "auto"},+ "additional_drop_params": ["reasoning.nope"],+ }++ result = ResponsesAPIRequestUtils.get_requested_response_api_optional_param(params)++ assert result["reasoning"] == {"effort": "high", "summary": "auto"}++ def test_get_requested_response_api_optional_param_none_drop_params(self):+ """additional_drop_params=None is a no-op"""+ params = {+ "reasoning": {"effort": "high", "summary": "auto"},+ "additional_drop_params": None,+ }++ result = ResponsesAPIRequestUtils.get_requested_response_api_optional_param(params)++ assert result["reasoning"] == {"effort": "high", "summary": "auto"}+def test_decode_previous_response_id_to_original_previous_response_id(self):"""Test decoding a LiteLLM encoded previous_response_id to the original previous_response_id"""# Setup