> ## Documentation Index
> Fetch the complete documentation index at: https://langchain-5e9cc07a-preview-docscl-1781043860-248c713.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# PerplexitySearchResults integration

> Integrate with the PerplexitySearchResults tool using LangChain JavaScript.

The [Perplexity Search API](https://docs.perplexity.ai/docs/search/quickstart) returns real-time, grounded web search results. `PerplexitySearchResults` is a LangChain [tool](/oss/javascript/integrations/tools/) wrapper that lets agents query the API and receive a JSON array of search results.

## Overview

### Integration details

| Class                                                                                                                | Package                                                                        | [PY support](https://python.langchain.com/docs/integrations/tools/perplexity_search/) |                                               Version                                              |
| :------------------------------------------------------------------------------------------------------------------- | :----------------------------------------------------------------------------- | :-----------------------------------------------------------------------------------: | :------------------------------------------------------------------------------------------------: |
| [`PerplexitySearchResults`](https://reference.langchain.com/javascript/langchain-perplexity/PerplexitySearchResults) | [`@langchain/perplexity`](https://www.npmjs.com/package/@langchain/perplexity) |                                           ✅                                           | ![NPM - Version](https://img.shields.io/npm/v/@langchain/perplexity?style=flat-square\&label=%20&) |

## Setup

The integration lives in the `@langchain/perplexity` package:

<CodeGroup>
  ```bash npm theme={null}
  npm install @langchain/perplexity @langchain/core
  ```

  ```bash yarn theme={null}
  yarn add @langchain/perplexity @langchain/core
  ```

  ```bash pnpm theme={null}
  pnpm add @langchain/perplexity @langchain/core
  ```
</CodeGroup>

### Credentials

Set up a [Perplexity API key](https://www.perplexity.ai/account/api/keys) and set it as an environment variable named `PERPLEXITY_API_KEY`:

```typescript theme={null}
process.env.PERPLEXITY_API_KEY = "your-api-key";
```

It's also helpful (but not needed) to set up [LangSmith](https://smith.langchain.com/?utm_source=docs\&utm_medium=cta\&utm_campaign=langsmith-signup\&utm_content=oss-javascript-integrations-tools-perplexity_search) for best-in-class observability:

```typescript theme={null}
process.env.LANGSMITH_TRACING = "true";
process.env.LANGSMITH_API_KEY = "your-api-key";
```

## Instantiation

```typescript theme={null}
import { PerplexitySearchResults } from "@langchain/perplexity";

const tool = new PerplexitySearchResults({
  maxResults: 5,
  // searchDomainFilter: ["wikipedia.org"],
  // searchRecencyFilter: "week",
});
```

Constructor options include `maxResults`, `country`, `searchDomainFilter`, `searchRecencyFilter`, `searchAfterDate`, and `searchBeforeDate`. See the [Perplexity Search API parameters](https://docs.perplexity.ai/docs/search/quickstart) for details.

## Invocation

### Direct call

```typescript theme={null}
const result = await tool.invoke("Who won the most recent FIFA World Cup?");
console.log(result);
```

The tool returns a JSON-encoded array of search results, each with `title`, `url`, `snippet`, `date`, and `last_updated`.

### Use with an agent

```typescript theme={null}
import { ChatAnthropic } from "@langchain/anthropic";
import { createReactAgent } from "@langchain/langgraph/prebuilt";

const llm = new ChatAnthropic({ model: "claude-3-5-haiku-latest" });

const agent = createReactAgent({
  llm,
  tools: [tool],
});

const response = await agent.invoke({
  messages: [
    { role: "user", content: "What's the latest news on the Mars Sample Return mission?" },
  ],
});
```

## API reference

For detailed documentation of all `PerplexitySearchResults` features and configurations head to the [API reference](https://reference.langchain.com/javascript/langchain-perplexity/PerplexitySearchResults).

***

<div className="source-links">
  <Callout icon="terminal-2">
    [Connect these docs](/use-these-docs) to Claude, VSCode, and more via MCP for real-time answers.
  </Callout>

  <Callout icon="edit">
    [Edit this page on GitHub](https://github.com/langchain-ai/docs/edit/main/src/oss/javascript/integrations/tools/perplexity_search.mdx) or [file an issue](https://github.com/langchain-ai/docs/issues/new/choose).
  </Callout>
</div>
