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
[Bug Fix] Perplexity - LiteLLM doesn't support 'web_search_options' for Perplexity' Sonar Pro model (#11983)
Ishaan Jaffef7f8cce9340
diff --git a/litellm/llms/perplexity/chat/transformation.py b/litellm/llms/perplexity/chat/transformation.pyindex 4ce2df51b6e..a81400870a7 100644--- a/litellm/llms/perplexity/chat/transformation.py+++ b/litellm/llms/perplexity/chat/transformation.py@@ -55,4 +55,13 @@ class PerplexityChatConfig(OpenAIGPTConfig):base_openai_params.append("reasoning_effort")except Exception as e:verbose_logger.debug(f"Error checking if model supports reasoning: {e}")++ try:+ if litellm.supports_web_search(+ model=model, custom_llm_provider=self.custom_llm_provider+ ):+ base_openai_params.append("web_search_options")+ except Exception as e:+ verbose_logger.debug(f"Error checking if model supports web search: {e}")+return base_openai_paramsdiff --git a/tests/test_litellm/llms/perplexity/test_perplexity.py b/tests/test_litellm/llms/perplexity/test_perplexity.pynew file mode 100644index 00000000000..5c8eead4d6d--- /dev/null+++ b/tests/test_litellm/llms/perplexity/test_perplexity.py@@ -0,0 +1,25 @@+import os+import sys++sys.path.insert(0, os.path.abspath("../../.."))++import pytest+++class TestPerplexityWebSearch:+ """Test suite for Perplexity web search functionality."""++ @pytest.mark.parametrize(+ "model",+ ["perplexity/sonar", "perplexity/sonar-pro"]+ )+ def test_web_search_options_in_supported_params(self, model):+ """+ Test that web_search_options is in the list of supported parameters for Perplexity sonar models+ """+ from litellm.llms.perplexity.chat.transformation import PerplexityChatConfig++ config = PerplexityChatConfig()+ supported_params = config.get_supported_openai_params(model=model)++ assert "web_search_options" in supported_params, f"web_search_options should be supported for {model}"