Overview
LangChain is a framework for building LLM applications, and LangGraph adds stateful agents on top of it. Reach Perplexity’s Agent API throughlangchain-openai’s ChatOpenAI with use_responses_api=True, pointed at Perplexity’s base URL.
Use
ChatOpenAI from langchain-openai — not ChatPerplexity from langchain-perplexity, which only speaks Sonar Chat Completions.
Setting use_responses_api=True routes calls to POST /v1/responses (the Agent API).Installation
API Key Setup
Get API Key
Generate your Perplexity API key from the API portal.
Chat Model
PointChatOpenAI at Perplexity’s /v1 base URL and enable the built-in web_search tool for grounded answers:
Pass Perplexity’s built-in tools (
web_search, fetch_url) 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.
preset="medium" selects a deep-research configuration; see Presets for faster, lighter options like fast and low.LangGraph Agent
Drop the grounded model into a LangGraph agent. Becauseweb_search runs server-side, no client-side tools are required:
Reading Sources
To read structuredsearch_results (titles and URLs), call the Agent API directly with the Perplexity SDK:
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.