Two integration paths both talk to Perplexity’s Agent API:
langchain-perplexitywith the nativeChatPerplexityclass anduse_responses_api=True. Shorter constructor, no base URL to configure. This is the path in the code samples below. Requireslangchain-perplexity1.4.1 or later.langchain-openaiwithChatOpenAIpointed at Perplexity’s base URL. Also works today onlangchain-openai1.5.x. See langchain-openai alternate path.
Installation
langchain 1.0 or later provides create_agent and installs LangGraph automatically. langchain-perplexity 1.4.1 or later provides ChatPerplexity with use_responses_api=True.
API Key Setup
Get API Key
Generate your Perplexity API key from the API portal.
Chat Model
UseChatPerplexity with use_responses_api=True to route calls to Perplexity’s Agent API. Pass the built-in web_search tool for grounded answers.
response.text is a property. Do not call response.text().
Selecting a model or preset
ChatPerplexity(use_responses_api=True) sends the call to the Agent API, so pick one of two ways to select routing:
- Pass a
presetthroughmodel_kwargs. Presets are"fast","low","medium","high","xhigh", and"wide-research". The preset chooses the current recommended model plus tool defaults for that tier. See Presets for the full list. - Set
model=explicitly to an Agent API model such asopenai/gpt-5.6-sol. See Agent API models.
model= overrides the preset’s default model while keeping the preset’s other defaults.
Passing Perplexity built-in tools and options
Route Perplexity’s built-in tools (web_search, fetch_url) and Agent-API-only fields (like preset) through model_kwargs. That keeps everything the Agent API needs in one place.
ChatPerplexity reads PERPLEXITY_API_KEY from the environment and targets Perplexity’s Agent API directly, so you do not set base_url.Filtering web search
Web search filters live inside afilters object on the web_search tool config:
web_search tool docs for the full filter reference, including domain allowlist and denylist rules and date-range filters.
LangChain Agent
Create an agent withcreate_agent from langchain.agents. Do not use langgraph.prebuilt.create_react_agent; that path is deprecated. Pass Perplexity’s built-in tools in the agent’s tools list.
create_agent tools list, including Perplexity built-ins and any local tools:
tools list to the model, so keep tools there rather than in model_kwargs.
Reading Sources
To read structuredsearch_results with titles and URLs, call the Agent API directly with the Perplexity SDK:
langchain-openai Alternate Path
If you already uselangchain-openai, point ChatOpenAI at Perplexity’s /v1 base URL, set use_responses_api=True, and pass the built-in web_search tool through model_kwargs.
On
ChatOpenAI, pass Perplexity’s built-in tools through model_kwargs={"tools": [...]} and Agent-API-only fields such as preset through extra_body. The underlying OpenAI SDK rejects them as unknown top-level keyword arguments.Links & Resources
Agent API Quickstart
Build with Agent API models, tools, and presets.
Agent API Models
Available models and pricing.
LangGraph Docs
Build stateful agents with LangGraph.