diff --git a/litellm/responses/main.py b/litellm/responses/main.py index db8a03de707..93bc41f3646 100644 --- a/litellm/responses/main.py +++ b/litellm/responses/main.py @@ -415,7 +415,6 @@ def _bridge_kwargs( responses_api_provider_config: BaseResponsesAPIConfig | None, allowed_openai_params: Sequence[str] | None, ) -> Mapping[str, object]: - """Drop the provider-specific kwargs a native Responses dispatch would never forward, unless explicitly allowed.""" if responses_api_provider_config is None: return kwargs forwarded_keys: Final = frozenset( diff --git a/tests/test_litellm/responses/test_responses_api_bridge_flag.py b/tests/test_litellm/responses/test_responses_api_bridge_flag.py index f3aac074e49..2f64cc8debc 100644 --- a/tests/test_litellm/responses/test_responses_api_bridge_flag.py +++ b/tests/test_litellm/responses/test_responses_api_bridge_flag.py @@ -192,33 +192,44 @@ class TestUseResponsesApiBridgeFlag: ] @pytest.mark.parametrize( - ("provider_config", "allowed_openai_params", "expected_chat_template_kwargs"), + ("model", "upstream_url", "use_chat_completions_api", "allowed_openai_params", "expected_chat_template_kwargs"), [ - pytest.param(litellm.OpenAIResponsesAPIConfig(), None, None, id="native-config-drops-unknown-param"), pytest.param( - litellm.OpenAIResponsesAPIConfig(), + "openai/my-custom-model", + "https://api.openai.com/v1/chat/completions", + True, + None, + None, + id="native-config-drops-unknown-param", + ), + pytest.param( + "openai/my-custom-model", + "https://api.openai.com/v1/chat/completions", + True, ["chat_template_kwargs"], {"thinking": True}, id="native-config-keeps-allowed-param", ), - pytest.param(None, None, {"thinking": True}, id="no-native-config-keeps-passthrough"), + pytest.param( + "together_ai/my-custom-model", + "https://api.together.ai/v1/chat/completions", + False, + None, + {"thinking": True}, + id="no-native-config-keeps-passthrough", + ), ], ) - @patch.object(import_module("litellm.responses.main").ProviderConfigManager, "get_provider_responses_api_config") def test_bridge_forwards_same_params_as_native_dispatch( self, - mock_get_config, - provider_config, - allowed_openai_params, - expected_chat_template_kwargs, + model: str, + upstream_url: str, + use_chat_completions_api: bool, + allowed_openai_params: list[str] | None, + expected_chat_template_kwargs: dict[str, bool] | None, respx_mock: respx.MockRouter, ): - """A deployment-supplied provider-specific kwarg (``chat_template_kwargs``) reaches the - provider through the bridge only when the native Responses path would forward it too: - never for a provider with a native config, unless the caller allowed it explicitly, and - always for a provider without one, whose only Responses path is the bridge.""" - mock_get_config.return_value = provider_config - upstream: Final = respx_mock.post("https://api.openai.com/v1/chat/completions").mock( + upstream: Final = respx_mock.post(upstream_url).mock( return_value=httpx.Response( status_code=200, json={ @@ -235,13 +246,13 @@ class TestUseResponsesApiBridgeFlag: ) response: Final = litellm.responses( - model="openai/my-custom-model", + model=model, input="Hello", - use_chat_completions_api=True, + use_chat_completions_api=use_chat_completions_api, allowed_openai_params=allowed_openai_params, chat_template_kwargs={"thinking": True}, drop_params=True, - api_key="fake-openai-api-key", + api_key="fake-provider-api-key", num_retries=0, ) @@ -252,8 +263,6 @@ class TestUseResponsesApiBridgeFlag: assert response.output[0].content[0].text == "Answer" def test_bridge_keeps_deployment_credentials_while_dropping_unknown_params(self, respx_mock: respx.MockRouter): - """Azure has a native Responses config, so its bridged request drops the unknown param but still - authenticates with the deployment credential, which the native path reads from the same kwargs.""" upstream: Final = respx_mock.post( "https://example-resource.openai.azure.com/openai/deployments/my-deployment/chat/completions", params={"api-version": "2024-10-21"},