> ## Documentation Index
> Fetch the complete documentation index at: https://agno-v2.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Perplexity

> Use Perplexity models with built-in web search in Agno agents.

Perplexity offers language models with built-in web search for research and Q\&A.

Explore Perplexity's models [here](https://docs.perplexity.ai/guides/model-cards).

## Installation

```bash theme={null}
uv pip install -U openai agno
```

## Authentication

Set your `PERPLEXITY_API_KEY` environment variable. Get your key [from Perplexity here](https://www.perplexity.ai/settings/api).

```bash Mac theme={null}
export PERPLEXITY_API_KEY=***
```

```bash Windows theme={null}
setx PERPLEXITY_API_KEY ***
```

## Example

Use `Perplexity` with your `Agent`:

```python agent.py theme={null}
from agno.agent import Agent
from agno.models.perplexity import Perplexity

agent = Agent(model=Perplexity(id="sonar-pro"), markdown=True)

# Print the response in the terminal
agent.print_response("Share a 2 sentence horror story")

```

> [!NOTE]
>
> View more examples [here](https://agno-v2.mintlify.site/models/providers/native/perplexity/usage/basic.md).

## Params

| Parameter | Type | Default | Description |
| - | - | - | - |
| `id` | `str` | `"sonar"` | The ID of the Perplexity model to use |
| `name` | `str` | `"Perplexity"` | The name of the model |
| `provider` | `str` | `"Perplexity"` | The provider of the model |
| `api_key` | `Optional[str]` | `None` | The API key for Perplexity (defaults to PERPLEXITY\_API\_KEY env var) |
| `base_url` | `str` | `"https://api.perplexity.ai/"` | The base URL for the Perplexity API |
| `max_tokens` | `int` | `1024` | Maximum number of tokens to generate |
| `top_k` | `Optional[float]` | `None` | Number of highest probability tokens to consider for generation |
| `collect_metrics_on_completion` | `bool` | `True` | Collect token metrics only from the final streaming chunk (for providers with cumulative token counts) |

`Perplexity` also supports the params of [OpenAI](https://agno-v2.mintlify.site/reference/models/openai.md).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.