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.

Installation

uv pip install -U openai agno

Authentication

Set your PERPLEXITY_API_KEY environment variable. Get your key from Perplexity here.

export PERPLEXITY_API_KEY="YOUR_API_KEY"

Example

Use Perplexity with your Agent:

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")
View more examples here.

Params

ParameterTypeDefaultDescription
idstr"sonar"The ID of the Perplexity model to use
namestr"Perplexity"The name of the model
providerstr"Perplexity"The provider of the model
api_keyOptional[str]NoneThe API key for Perplexity (defaults to PERPLEXITY_API_KEY env var)
base_urlstr"https://api.perplexity.ai/"The base URL for the Perplexity API
max_tokensint1024Maximum number of tokens to generate
top_kOptional[float]NoneDeclared field; currently fails in the OpenAI SDK. Use the request_params workaround below
collect_metrics_on_completionboolTrueCollect token metrics only from the final streaming chunk (for providers with cumulative token counts)

The adapter forwards max_tokens, temperature, top_p, presence_penalty, frequency_penalty, and structured-output configuration. It inherits OpenAI client settings, but does not forward every OpenAI request field. In particular, extra_body on the model is ignored, and the direct top_k field currently becomes an unsupported SDK keyword. Send provider-specific body fields through request_params instead:

from agno.models.perplexity import Perplexity

model = Perplexity(
    id="sonar-pro",
    request_params={"extra_body": {"top_k": 5, "search_recency_filter": "month"}},
)

Sonar's built-in web search is separate from Agno function tools. The current Perplexity adapter does not forward Agno tool definitions. Use eager knowledge retrieval with add_knowledge_to_context=True and search_knowledge=False, and an explicit tool-capable MemoryManager model for memory extraction.