Skip to main content
This page will help you get started with Perplexity chat models. For detailed documentation of all ChatPerplexity features and configurations head to the API reference.

Overview

Integration details

Model features

Setup

To access Perplexity models you’ll need to create a Perplexity account, get an API key, and install the langchain-perplexity integration package.

Credentials

Head to this page to sign up for Perplexity and generate an API key. Once you’ve done this set the PPLX_API_KEY environment variable:
To enable automated tracing of your model calls, set your LangSmith API key:
The code provided assumes that your PPLX_API_KEY is set in your environment variables. If you would like to manually specify your API key and also choose a different model, you can use the following code:
You can check a list of available models here. For reproducibility, we can set the API key dynamically by taking it as an input in this notebook.
You can format and structure the prompts like you would typically. In the following example, we ask the model to tell us a joke about cats.

Using Perplexity-specific parameters through ChatPerplexity

You can also use Perplexity-specific parameters through the ChatPerplexity class. For example, parameters like search_domain_filter, return_images, return_related_questions or search_recency_filter using the extra_body parameter as shown below:

Accessing the search results metadata

Perplexity often provides a list of the web pages it consulted (“search_results”). You don’t need to pass any special parameter — the list is placed in response.additional_kwargs["search_results"].

ChatPerplexity also supports streaming functionality

ChatPerplexity Supports Structured Outputs for Tier 3+ Users


Connect these docs programmatically to Claude, VSCode, and more via MCP for real-time answers.