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

# Perplexity

> LLM service implementation using Perplexity's API with OpenAI-compatible interface

## Overview

`PerplexityLLMService` provides access to Perplexity's language models through an OpenAI-compatible interface. It inherits from `OpenAILLMService` and supports streaming responses and context management, with special handling for Perplexity's incremental token reporting and built-in internet search capabilities.

<CardGroup cols={2}>
  <Card title="Perplexity LLM API Reference" icon="code" href="https://reference-server.pipecat.ai/en/latest/api/pipecat.services.perplexity.llm.html">
    Pipecat's API methods for Perplexity integration
  </Card>

  <Card title="Example Implementation" icon="play" href="https://github.com/pipecat-ai/pipecat/blob/main/examples/function-calling/function-calling-perplexity.py">
    Complete example with search capabilities
  </Card>

  <Card title="Perplexity Documentation" icon="book" href="https://docs.perplexity.ai/api-reference/chat-completions-post">
    Official Perplexity API documentation and features
  </Card>

  <Card title="Perplexity Platform" icon="microphone" href="https://www.perplexity.ai/">
    Access search-enhanced models and API keys
  </Card>
</CardGroup>

## Installation

To use Perplexity services, install the required dependencies:

```bash theme={null}
uv add "pipecat-ai[perplexity]"
```

## Prerequisites

### Perplexity Account Setup

Before using Perplexity LLM services, you need:

1. **Perplexity Account**: Sign up at [Perplexity](https://www.perplexity.ai/)
2. **API Key**: Generate an API key from your account dashboard
3. **Model Selection**: Choose from available models with built-in search capabilities

### Required Environment Variables

* `PERPLEXITY_API_KEY`: Your Perplexity API key for authentication

<Note>
  Unlike other LLM services, Perplexity does not support function calling.
  Instead, they offer native internet search built in without requiring special
  function calls.
</Note>

## Configuration

<ParamField path="api_key" type="str" required>
  Perplexity API key for authentication.
</ParamField>

<ParamField path="base_url" type="str" default="https://api.perplexity.ai">
  Base URL for Perplexity API endpoint.
</ParamField>

<ParamField path="model" type="str" default="None" deprecated>
  *Deprecated in v0.0.105. Use
  `settings=PerplexityLLMService.Settings(model=...)` instead.*
</ParamField>

<ParamField path="settings" type="PerplexityLLMService.Settings" default="None">
  Runtime-configurable settings. See [Settings](#settings) below.
</ParamField>

### Settings

Runtime-configurable settings passed via the `settings` constructor argument using `PerplexityLLMService.Settings(...)`. These can be updated mid-conversation with `LLMUpdateSettingsFrame`. See [Service Settings](/pipecat/fundamentals/service-settings) for details.

This service uses the same settings as `OpenAILLMService`. See [OpenAI LLM Settings](/api-reference/server/services/llm/openai#settings) for the full parameter reference.

## Usage

### Basic Setup

```python theme={null}
import os
from pipecat.services.perplexity import PerplexityLLMService

llm = PerplexityLLMService(
    api_key=os.getenv("PERPLEXITY_API_KEY"),
    model="sonar",
)
```

### With Custom Settings

```python theme={null}
from pipecat.services.perplexity import PerplexityLLMService

llm = PerplexityLLMService(
    api_key=os.getenv("PERPLEXITY_API_KEY"),
    settings=PerplexityLLMService.Settings(
        model="sonar",
        temperature=0.7,
        top_p=0.9,
        max_tokens=1024,
    ),
)
```

## Notes

* Perplexity does not support function calling or tools. The service only sends messages to the API, without tool definitions.
* Perplexity uses incremental token reporting. The service accumulates token usage metrics during processing and reports the final totals at the end of each request.
* Perplexity models have built-in internet search capabilities, providing up-to-date information without requiring additional tool configuration.
* **Message transformation**: Perplexity's API enforces stricter constraints than OpenAI on conversation history structure (strict role alternation, no non-initial system messages, last message must be user/tool). The service automatically transforms messages to satisfy these constraints before sending them to the API, so you don't need to manually structure your conversation history.

<Tip>
  The `InputParams` / `params=` pattern is deprecated as of v0.0.105. Use
  `Settings` / `settings=` instead. See the [Service Settings
  guide](/pipecat/fundamentals/service-settings) for migration details.
</Tip>
