diff --git a/litellm/main.py b/litellm/main.py index 09c70998cf7..e91dcaaf832 100644 --- a/litellm/main.py +++ b/litellm/main.py @@ -981,6 +981,19 @@ def responses_api_bridge_check( model_info["mode"] = "responses" model = model.replace("responses/", "") + # Auto-bridge to Responses API when web_search_options is requested + # and the model supports web search and the /v1/responses endpoint, + # but its current mode is not already "responses". The bridge + # converts web_search_options into a web_search_preview tool. + if ( + web_search_options is not None + and model_info.get("mode") != "responses" + and model_info.get("supports_web_search") is True + and "/v1/responses" + in (model_info.get("supported_endpoints") or []) + ): + model_info["mode"] = "responses" + except Exception as e: verbose_logger.debug("Error getting model info: {}".format(e)) @@ -1554,6 +1567,20 @@ def completion( # type: ignore # noqa: PLR0915 "allowed_openai_params": kwargs.get("allowed_openai_params"), "base_model": base_model, } + + # If the model will be bridged to the Responses API, allow params + # that the bridge can handle (e.g. web_search_options) even if the + # provider's chat/completions config doesn't list them. + if responses_api_model_info.get("mode") == "responses": + _bridge_params = [] + if web_search_options is not None: + _bridge_params.append("web_search_options") + if _bridge_params: + existing = optional_param_args.get("allowed_openai_params") or [] + optional_param_args["allowed_openai_params"] = list( + set(existing + _bridge_params) + ) + optional_params = get_optional_params( **optional_param_args, **non_default_params ) diff --git a/litellm/types/utils.py b/litellm/types/utils.py index a0d8f78b3b3..26f41200d4e 100644 --- a/litellm/types/utils.py +++ b/litellm/types/utils.py @@ -151,6 +151,7 @@ class ProviderSpecificModelInfo(TypedDict, total=False): bedrock_output_config_effort_ceiling: Optional[ Literal["low", "medium", "high", "max", "xhigh"] ] + supported_endpoints: Optional[list] class SearchContextCostPerQuery(TypedDict, total=False): diff --git a/litellm/utils.py b/litellm/utils.py index 0a2bf532281..18506b4218c 100644 --- a/litellm/utils.py +++ b/litellm/utils.py @@ -6063,6 +6063,7 @@ def _get_model_info_helper( # noqa: PLR0915 bedrock_output_config_effort_ceiling=_model_info.get( "bedrock_output_config_effort_ceiling", None ), + supported_endpoints=_model_info.get("supported_endpoints", None), supports_computer_use=_model_info.get("supports_computer_use", None), search_context_cost_per_query=_model_info.get( "search_context_cost_per_query", None