From 287bea4240cc011f61c8d964609508751fea2f6b Mon Sep 17 00:00:00 2001 From: Terrajlz Date: Fri, 22 May 2026 13:56:24 -0400 Subject: [PATCH] fix: filter internal _-prefixed flags for non-OpenAI providers too The else branch (non-OpenAI/Azure providers) in add_provider_specific_params_to_optional_params was not filtering underscore-prefixed internal flags, only the if branch (OpenAI/Azure) was. Added the same `not k.startswith("_")` guard and a test with custom_llm_provider="anthropic" to cover this path. Addresses greptile review concern about missing non-OpenAI provider test coverage. --- litellm/utils.py | 6 +++++- ...est_websearch_interception_stream_param.py | 21 +++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/litellm/utils.py b/litellm/utils.py index da524433ae7..320620b10f8 100644 --- a/litellm/utils.py +++ b/litellm/utils.py @@ -4869,7 +4869,11 @@ def add_provider_specific_params_to_optional_params( ) else: for k in passed_params.keys(): - if k not in openai_params and passed_params[k] is not None: + if ( + k not in openai_params + and passed_params[k] is not None + and not k.startswith("_") + ): if _should_drop_param( k=k, additional_drop_params=additional_drop_params ): diff --git a/tests/test_litellm/test_websearch_interception_stream_param.py b/tests/test_litellm/test_websearch_interception_stream_param.py index 4421a6e97ac..abddcd9d4bb 100644 --- a/tests/test_litellm/test_websearch_interception_stream_param.py +++ b/tests/test_litellm/test_websearch_interception_stream_param.py @@ -103,6 +103,27 @@ class TestInternalFlagsNotInExtraBody: assert "_websearch_interception_converted_stream" not in extra_body assert extra_body.get("custom_param") == "value" + def test_non_openai_provider_flags_excluded(self): + """Internal flags should also be filtered for non-OpenAI providers (else branch).""" + passed_params = { + "_websearch_interception_converted_stream": True, + "_other_internal": "skip", + "custom_param": "keep", + } + optional_params = {} + openai_params = ["model", "messages"] + + result = add_provider_specific_params_to_optional_params( + optional_params=optional_params, + passed_params=passed_params, + custom_llm_provider="anthropic", + openai_params=openai_params, + ) + + assert "_websearch_interception_converted_stream" not in result + assert "_other_internal" not in result + assert result.get("custom_param") == "keep" + def test_no_extra_body_when_only_internal_flags(self): """If only internal flags exist (besides openai params), extra_body should be empty.""" passed_params = {