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 agnoAuthentication
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")
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 | Declared field; currently fails in the OpenAI SDK. Use the request_params workaround below |
collect_metrics_on_completion | bool | True | Collect 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.