Overview
LangChain provides first-class integrations for Perplexity in both Python (langchain-perplexity) and JavaScript/TypeScript (@langchain/community). Both packages let you build LLM applications with real-time web search, citations, and Perplexity’s Pro Search reasoning.
LangChain is a popular Python framework for building applications powered by large language models. It provides composable components for chains, agents, and retrieval-augmented generation (RAG). Learn more at langchain.com.
- ChatPerplexity - Chat model with Pro Search, streaming, and search controls
- PerplexitySearchRetriever - Retriever for RAG applications
- PerplexitySearchResults - Tool for LangChain agents
Installation
- pip
- uv
API Key Setup
Set your Perplexity API key as an environment variable:Get API Key
Generate your Perplexity API key from the API portal.
Quick Start: Chat Models
UseChatPerplexity for conversational AI with web search:
Pro Search
Enable multi-step reasoning with Pro Search:Search Controls
Filter search results by domain, recency, or date:Streaming
Quick Start: Retriever
UsePerplexitySearchRetriever for RAG applications:
RAG Chain Example
Quick Start: Tool
UsePerplexitySearchResults with LangChain agents:
Agent Example
JavaScript / TypeScript
The JavaScript integration ships in the@langchain/community package as ChatPerplexity. It is an OpenAI-compatible chat model that talks to https://api.perplexity.ai.
Installation
- npm
- pnpm
- yarn
API Key Setup
SetPERPLEXITY_API_KEY in your environment, or pass apiKey directly to the constructor:
Quick Start
Streaming
Chaining with Prompts
Available Models
The integration supports all Perplexity models:| Model | Description |
|---|---|
sonar | Fast, cost-effective search model |
sonar-pro | Advanced model with Pro Search support |
sonar-reasoning-pro | Advanced reasoning capabilities |
sonar-deep-research | Deep research with comprehensive analysis |
Links & Resources
LangChain Docs
Full LangChain integration documentation
ChatPerplexity
Detailed chat model documentation
Retriever Docs
PerplexitySearchRetriever documentation
Tool Docs
PerplexitySearchResults documentation
PyPI Package
View on PyPI
API Reference
LangChain API reference
LangChain JS Docs
ChatPerplexity for JavaScript / TypeScript
npm Package
@langchain/community on npm
Support
Need help with the integration?- Check the LangChain documentation
- Review our FAQ