Skip to main content

Overview

The langchain-perplexity package provides LangChain integrations for Perplexity’s API, enabling you to build LLM applications with real-time web search capabilities.
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.
The integration includes:
  • ChatPerplexity - Chat model with Pro Search, streaming, and search controls
  • PerplexitySearchRetriever - Retriever for RAG applications
  • PerplexitySearchResults - Tool for LangChain agents

Installation

API Key Setup

Set your Perplexity API key as an environment variable:

Get API Key

Generate your API key from the Perplexity dashboard.

Quick Start: Chat Models

Use ChatPerplexity for conversational AI with web search:
Enable multi-step reasoning with Pro Search:

Search Controls

Filter search results by domain, recency, or date:

Streaming

Quick Start: Retriever

Use PerplexitySearchRetriever for RAG applications:

RAG Chain Example

Quick Start: Tool

Use PerplexitySearchResults with LangChain agents:

Agent Example

Available Models

The integration supports all Perplexity models: See the full list of models on our models page.

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

Support

Need help with the integration?