Skip to main content
Perplexity Search is a web search API that returns ranked, source-attributed results designed for use by LLMs and agents. It powers the answer engine at perplexity.ai and is exposed through the dedicated Search API endpoint. This page goes over how to use the Perplexity Search API as a LangChain tool.

Setup

Installation

Install the LangChain Perplexity integration package:

Credentials

You’ll need a Perplexity API key to use this integration. Create one in the Perplexity API key dashboard.
The integration also accepts PERPLEXITY_API_KEY if you prefer that name.

Using PerplexitySearchResults tool

PerplexitySearchResults is a tool that can be used with LangChain agents to perform Perplexity searches. Calling it returns a JSON array of search results, each containing a title, url, snippet, date, and last_updated field.

Advanced features for PerplexitySearchResults

The tool accepts the following constructor and call-time arguments:
  • max_results — number of results to return.
  • country — ISO country code to bias results (e.g. "US").
  • search_domain_filter — list of domains to include or exclude (max 20). Prefix a domain with - to exclude it. See the domain filter docs.
  • search_recency_filter — one of "day", "week", "month", "year". See the date and time filter docs.
  • search_after_date / search_before_date — date strings in MM/DD/YYYY format.

Use within an Agent

We can use the PerplexitySearchResults tool with a LangGraph agent. This gives the agent the ability to dynamically search the web for grounded, source-attributed information. First, set up the language model. You’ll need to provide your OpenAI API key:

API reference

For detailed documentation of the Perplexity Search API and all of its options, see the Search API reference and the Perplexity API documentation.