Prerequisites
The following example requires thehttpx library and an API key from Perplexity.
Examples
Basic search:When to Use
Use PerplexitySearch when you need:- Current, ranked web search results with publication dates
- Filtering by recency (past day, week, month, or year)
- Restriction to specific domains or languages
- Integration with agents that need up-to-date information
Toolkit Params
| Parameter | Type | Default | Description |
|---|---|---|---|
api_key | Optional[str] | None | Perplexity API key. If not provided, uses PERPLEXITY_API_KEY environment variable. |
max_results | int | 5 | Maximum number of results to return per query. |
max_tokens_per_page | int | 2048 | Maximum content length per result in tokens. |
search_recency_filter | Optional[str] | None | Filter results by recency: day, week, month, or year. |
search_domain_filter | Optional[List[str]] | None | List of domains to restrict search results to. |
search_language_filter | Optional[List[str]] | None | List of ISO language codes to filter results by language. |
show_results | bool | False | Log search results for debugging. |
Toolkit Functions
| Function | Description |
|---|---|
search | Search the web using the Perplexity Search API. Takes a query (str) and optional max_results (int). Returns a JSON array of results with url, title, snippet, and date. |
asearch | Async variant of search. Uses httpx.AsyncClient for non-blocking requests. |