Skip to main content
This guide 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

See the links in the table headers below for guides on how to use specific features. Note that at the time of writing, Perplexity only supports structured outputs on certain usage tiers.

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 the Perplexity API key dashboard to sign up and generate an API key. Once you’ve done this set the PERPLEXITY_API_KEY environment variable:
If you want to get automated tracing of your model calls you can also set your LangSmith API key by uncommenting below:

Installation

The LangChain Perplexity integration lives in the @langchain/perplexity package:

Instantiation

Now you can instantiate the model:

Invocation

Agent API support (useResponsesApi)

ChatPerplexity can also route requests through Perplexity’s Agent API (the Perplexity-flavored Responses API) by setting useResponsesApi. This mirrors ChatOpenAI’s Responses pattern: one class, two endpoints, controlled by a single option. 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 (previousResponseId, instructions, include) which are not available on Chat Completions. Existing new ChatPerplexity({ model: "sonar" }) callers see no behavior change — the Chat Completions path stays the default for plain text requests.
You can also bind a built-in tool and let auto-detection route the request — no option 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, object) along with Perplexity-specific search outputs when present: citations, images, related_questions, and search_results.
  • additional_kwargs.responses_output holds the raw Agent API output items.
  • Tool calls returned by the model surface on response.tool_calls exactly as they do for ChatOpenAI.
The _toResponsesPayload translation passes temperature, topP, and toolChoice straight through to the Agent API. Chat-Completions-only knobs that are not native Responses fields (for example topK, stop, metadata) are forwarded under extra_body.
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). The @langchain/perplexity package also includes search components that do not use the chat API: See the Perplexity provider overview for setup on all three components.

API reference

For detailed documentation of all ChatPerplexity features and configurations head to the API reference.