This guide will help you getting started with Perplexity chat models. For detailed documentation of allDocumentation Index
Fetch the complete documentation index at: https://langchain-5e9cc07a-preview-docsad-1779980884-cf903d3.mintlify.app/llms.txt
Use this file to discover all available pages before exploring further.
ChatPerplexity features and configurations head to the API reference.
Overview
Integration details
| Class | Package | Serializable | PY support | Downloads | Version |
|---|---|---|---|---|---|
ChatPerplexity | @langchain/community | beta | ✅ |
Model features
See the links in the table headers below for guides on how to use specific features.| Tool calling | Structured output | Image input | Audio input | Video input | Token-level streaming | Token usage | Logprobs |
|---|---|---|---|---|---|---|---|
| ❌ | ✅ | ❌ | ❌ | ❌ | ✅ | ✅ | ❌ |
Setup
To access Perplexity models you’ll need to create a Perplexity account, get an API key, and install the@langchain/community integration package.
Credentials
Head to https://perplexity.ai to sign up for Perplexity and generate an API key. Once you’ve done this set thePERPLEXITY_API_KEY environment variable:
Installation
The LangChain Perplexity integration lives in the@langchain/community package:
Instantiation
Now we can instantiate our model object and generate chat completions: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.
| Value | Endpoint | Notes |
|---|---|---|
undefined (default) | Auto-detected | Routes to the Agent API when the request uses a built-in Perplexity tool (web_search, fetch_url, finance_search, people_search) or includes a Responses-only field (previousResponseId, instructions, input, include). Otherwise routes to Chat Completions. |
true | Agent API | Always uses client.responses.create(). |
false | Chat Completions | Always uses client.chat.completions.create(). |
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.
usage_metadatais populated from the Responses-shapedusagepayload (input_tokens,output_tokens,total_tokens).response_metadatacarries transport-level fields (id,model,status,object) along with Perplexity-specific search outputs when present:citations,images,related_questions, andsearch_results.additional_kwargs.responses_outputholds the raw Agent API output items.- Tool calls returned by the model surface on
response.tool_callsexactly as they do forChatOpenAI.
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.openai/gpt-5.4, anthropic/claude-sonnet-4-6, google/gemini-3-1-pro).
API reference
For detailed documentation of allChatPerplexity features and configurations head to the API reference.
Connect these docs to Claude, VSCode, and more via MCP for real-time answers.

