Skip to content

[Feat] Add def search() APIs for Web Search - Perplexity API - #15769

Merged
ishaan-jaff merged 18 commits into
mainfrom
litellm_add_search_api
Oct 21, 2025
Merged

[Feat] Add def search() APIs for Web Search - Perplexity API #15769
ishaan-jaff merged 18 commits into
mainfrom
litellm_add_search_api

Conversation

@ishaan-jaff

@ishaan-jaff ishaan-jaff commented Oct 21, 2025

Copy link
Copy Markdown
Contributor

[Feat] Add def search() APIs for Web Search - Perplexity API

Summary

This PR adds a new unified Search API to LiteLLM, following the Perplexity Search API specification. The implementation provides a consistent interface for web search across providers, starting with Perplexity support.

Usage Examples

Basic Search

import litellm

# Synchronous search
response = litellm.search(
    query="latest AI developments 2024",
    custom_llm_provider="perplexity"
)

# Print results
for result in response.results:
    print(f"{result.title}: {result.url}")
    print(f"Snippet: {result.snippet}\n")

Async Search

import litellm
import asyncio

async def main():
    response = await litellm.asearch(
        query="latest AI developments",
        custom_llm_provider="perplexity"
    )
    
    for result in response.results:
        print(f"{result.title}: {result.url}")

asyncio.run(main())

Advanced Options

import litellm

# Search with filters and options
response = litellm.search(
    query="machine learning research",
    custom_llm_provider="perplexity",
    max_results=5,
    search_domain_filter=["arxiv.org", "nature.com"],
    max_tokens_per_page=1024,
    country="US"
)

Multi-Query Search

import litellm

# Search multiple queries at once
response = litellm.search(
    query=["AI developments", "machine learning trends"],
    custom_llm_provider="perplexity"
)

Environment Variables

# Set API key
export PERPLEXITYAI_API_KEY="your-api-key"

# Optional: Override API base
export PERPLEXITY_API_BASE="https://api.perplexity.ai"

Relevant issues

#15314

Pre-Submission checklist

Please complete all items before asking a LiteLLM maintainer to review your PR

  • I have Added testing in the tests/litellm/ directory, Adding at least 1 test is a hard requirement - see details
  • I have added a screenshot of my new test passing locally
  • My PR passes all unit tests on make test-unit
  • My PR's scope is as isolated as possible, it only solves 1 specific problem

Type

🆕 New Feature
✅ Test

Changes

@vercel

vercel Bot commented Oct 21, 2025

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
litellm Ready Ready Preview Comment Oct 21, 2025 9:18pm

@ishaan-jaff
ishaan-jaff merged commit e1cb928 into main Oct 21, 2025
45 of 53 checks passed
@ishaan-berri
ishaan-berri deleted the litellm_add_search_api branch March 26, 2026 21:51
fzowl pushed a commit to fzowl/litellm that referenced this pull request Jun 24, 2026
…#15769)

* add BaseSearchConfig

* add BaseSearchConfig

* validate_environment

* fix handlers

* add PerplexitySearchConfig

* add PerplexitySearchConfig

* add LiteLLM Search API module.

* add BaseSearchConfig

* add _build_search_optional_params

* add search_testing

* add BaseSearchTest

* add TestPerplexitySearch

* fix BASE

* fix handler

* add search API

* add to init

* fix: working perplexity search API

* add _hidden_params to search
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant