> ## Documentation Index
> Fetch the complete documentation index at: https://docs.perplexity.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Perplexity with CAMEL-AI

> Use the Perplexity Search API as a tool inside CAMEL-AI multi-agent systems.

## Overview

CAMEL-AI's `SearchToolkit` ships a `search_perplexity` method that wraps the [Perplexity Search API](https://docs.perplexity.ai/docs/search/quickstart.md) as a native CAMEL tool. The tool returns ranked web results with a title, URL, and snippet, plus publication and update dates when available, so the calling `ChatAgent` can ground its responses on fresh, citable sources.

> [!NOTE]
>
> **CAMEL-AI** is an open-source framework for building communicative multi-agent systems. Learn more at [camel-ai.org](https://www.camel-ai.org).

## Installation

```bash theme={null}
pip install "camel-ai==0.2.91a7"
```

Pin the prerelease. The latest stable release, `0.2.90`, does not include `SearchToolkit.search_perplexity`. `0.2.91a7` is the latest prerelease and it includes CAMEL's [compatibility bounds for `mcp` and `openai`](https://github.com/camel-ai/camel/pull/4313), so it installs without extra pins.

## API Key Setup

Set your Perplexity API key as an environment variable. `ChatAgent` also requires an API key for its model provider. CAMEL uses OpenAI by default, so the example below sets `OPENAI_API_KEY`. If you configure another model provider, set that provider's API key instead.

```bash theme={null}
export PERPLEXITY_API_KEY="your_api_key_here"
export OPENAI_API_KEY="your_openai_api_key_here"
```

> [card] [Get API Key](https://console.perplexity.ai/project/keys)
>
> Generate your API key from the Perplexity dashboard.

## Quick Start

Register `search_perplexity` as a tool on a `ChatAgent`:

```python theme={null}
from camel.agents import ChatAgent
from camel.toolkits import FunctionTool, SearchToolkit

agent = ChatAgent(
    system_message=(
        "You are a helpful assistant that can use the Perplexity "
        "search engine to answer questions."
    ),
    tools=[FunctionTool(SearchToolkit().search_perplexity)],
)

response = agent.step(
    input_message="What are the latest developments in multi-agent AI systems?",
    response_format=None,
)
print(response.msgs[0].content)
```

The tool calls `POST https://api.perplexity.ai/search` under the hood and returns the raw API response so the agent can pick which results to cite.

## Configuration

`search_perplexity` provides first-class arguments for `query`, `max_results`, `max_tokens`, `max_tokens_per_page`, `country`, `search_recency_filter`, `search_domain_filter`, and `search_language_filter`. Pass other Search API fields through `extra_params`.

```python theme={null}
from camel.toolkits import SearchToolkit

toolkit = SearchToolkit()

results = toolkit.search_perplexity(
    query="AI safety research",
    max_results=5,
    max_tokens_per_page=512,
    country="US",
    search_recency_filter="week",                         # hour | day | week | month | year
    search_domain_filter=["arxiv.org", "nature.com"],
    search_language_filter=["en"],
)
```

Domain filters can use either allowlist entries such as `"arxiv.org"` or denylist entries such as `"-medium.com"`, but you cannot mix allowlist and denylist modes in one request.

`query` can also be a list of up to five queries for batched search:

```python theme={null}
from camel.toolkits import SearchToolkit

toolkit = SearchToolkit()

results = toolkit.search_perplexity(
    query=["NVIDIA earnings", "AMD earnings"],
    max_results=3,
    extra_params={
        "search_after_date_filter": "1/1/2026",
        "search_before_date_filter": "5/1/2026",
    },
)
```

## Response Shape

`search_perplexity` returns the raw Perplexity Search API response as a `Dict[str, Any]`. On success, `id` and `results` are always present. `server_time` is optional: the response can omit it or set it to `None`. Each result requires `title`, `url`, and `snippet`; `date` and `last_updated` are optional and can be `None`.

```python theme={null}
{
    "id": "...",
    "server_time": "...",  # optional; may be omitted or None
    "results": [
        {
            "title": "...",
            "url": "...",
            "snippet": "...",
            "date": "...",          # optional; may be None
            "last_updated": "...",  # optional; may be None
        },
        # ...
    ],
}
```

If `PERPLEXITY_API_KEY` is missing, CAMEL raises `ValueError` before making a request. Non-200 responses, request exceptions, and response-decoding errors return a dictionary with an `error` key.

## Links & Resources

> [card] [CAMEL-AI Docs](https://docs.camel-ai.org)
>
> Build multi-agent systems with CAMEL-AI.

> [card] [Tool Source](https://github.com/camel-ai/camel/blob/v0.2.91a7/camel/toolkits/search_toolkit.py)
>
> SearchToolkit.search\_perplexity implementation.

> [card] [Search API Quickstart](https://docs.perplexity.ai/docs/search/quickstart.md)
>
> Learn more about the underlying Perplexity Search API.

> [card] [Example Script](https://github.com/camel-ai/camel/blob/v0.2.91a7/examples/toolkits/search_toolkit.py)
>
> End-to-end CAMEL example using Perplexity search.

## Support

Need help with the integration?

* Browse the [CAMEL-AI documentation](https://docs.camel-ai.org)
* Review our [FAQ](https://docs.perplexity.ai/docs/resources/faq.md)
