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 the list of available Perplexity models. 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.

Agent API support (use_responses_api)

ChatPerplexity can also route requests through Perplexity’s Agent API (the Perplexity-flavored Responses API) by setting use_responses_api. This is the same mental model as ChatOpenAI.use_responses_api: one class, two endpoints, controlled by a single flag. The Agent API gives ChatPerplexity access to Perplexity’s built-in tools (live web search, URL fetching, finance and people search) and stateful agent fields (previous_response_id, instructions, include) which are not available on Chat Completions. Existing ChatPerplexity(model="sonar") callers see no behavior change — the Chat Completions path stays the default for plain text requests.
You can also pass a built-in tool and let auto-detection route the request — no flag needed:
When routed through the Agent API, response objects carry richer metadata:
  • usage_metadata is populated from the Responses-shaped usage payload (input_tokens, output_tokens, total_tokens).
  • response_metadata carries transport-level fields: id, model, status, and object.
  • additional_kwargs surfaces Perplexity-specific outputs when present: citations, images, related_questions, search_results, videos, and reasoning_steps.
  • Tool calls returned by the model appear in response.tool_calls exactly as they do for ChatOpenAI.
The Agent API does not accept Chat-Completions-only sampling and control knobs. When ChatPerplexity routes through the Agent API (whether explicitly or by auto-detection), the following fields are dropped from the outgoing payload with a WARNING log: temperature, top_p, top_k, stop, and metadata. The class-default temperature is suppressed silently because _default_params injects it on every call, but a user-supplied temperature still warns.tool_choice is not silently dropped — it raises ValueError when routed through the Agent API, since downstream agent loops cannot recover from a missing forced-tool selection.
See the Perplexity Agent API model list for the full set of models available through this endpoint (e.g. openai/gpt-5.5, anthropic/claude-sonnet-4-6, google/gemini-3-1-pro).

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