TL;DR:
- Perplexity Sonar API wraps real-time web search with LLM synthesis into a single API call, returning answers with inline citations
- It’s faster and cheaper than chaining a search API with a separate LLM call when you need current information with sourcing
- Best used as a specialised tool in a larger agent system rather than as the only reasoning layer
Most AI agents deal with a familiar problem: their training data has a cutoff. Ask about a company’s latest funding round, a regulation published last month, or what a competitor announced yesterday, and you get either a confabulated answer or a polite refusal. The usual fix is RAG over a crawled corpus or plugging in a search tool. Perplexity’s Sonar API offers a more integrated path: a single API call that searches the live web, synthesises results, and returns an answer with citations already attached.
What Sonar Actually Does
Sonar is Perplexity’s API surface for their search-augmented LLM. When you POST a message to api.perplexity.ai/chat/completions, the model performs real-time web retrieval behind the scenes before generating a response. The returned answer includes a citations array with URLs to the sources used.
Three tiers exist as of 2026:
- sonar: Lightweight, fast, low cost. Good for quick lookups and classification tasks where you need current information.
- sonar-pro: Larger context, more thorough search across more sources. Better for multi-part research questions.
- sonar-reasoning: Adds chain-of-thought reasoning before generating the answer. Slower but meaningfully better on complex analytical questions.
The API is OpenAI-compatible, which matters for integration. You swap the base URL and model name, and existing agent frameworks that target OpenAI’s chat completions endpoint work with minimal changes.
Integration Pattern
Here’s a basic research tool using the Python requests library, structured as a callable function your agent can invoke:
import os
import requests
from typing import Optional
SONAR_API_KEY = os.environ["PERPLEXITY_API_KEY"]
def research_topic(
query: str,
model: str = "sonar-pro",
max_tokens: int = 1024,
recency_filter: Optional[str] = "week", # "hour", "day", "week", "month"
) -> dict:
"""
Query Perplexity Sonar for real-time research on a topic.
Returns synthesised answer with citations.
"""
response = requests.post(
"https://api.perplexity.ai/chat/completions",
headers={
"Authorization": f"Bearer {SONAR_API_KEY}",
"Content-Type": "application/json",
},
json={
"model": model,
"messages": [
{
"role": "system",
"content": (
"You are a research assistant. "
"Provide factual, concise answers with specific details. "
"Focus on the most recent and authoritative sources."
),
},
{"role": "user", "content": query},
],
"max_tokens": max_tokens,
"search_recency_filter": recency_filter,
"return_citations": True,
},
)
response.raise_for_status()
data = response.json()
return {
"answer": data["choices"][0]["message"]["content"],
"citations": data.get("citations", []),
"model": data["model"],
"usage": data["usage"],
}
The search_recency_filter parameter is genuinely useful for agent workflows. A competitive intelligence agent might use "day" when monitoring news; a deep-research agent building a background report can use "month" to cast a wider net.
Wiring It Into an Agent Framework
If you’re using LangChain or LlamaIndex, Sonar slots in as a standard tool. Here’s a LangChain tool definition:
from langchain.tools import Tool
sonar_tool = Tool(
name="web_research",
description=(
"Use this tool to research current events, company news, recent product "
"launches, regulatory updates, or any topic where up-to-date information "
"is important. Input should be a specific, focused search query. "
"Returns a synthesis with source citations."
),
func=lambda query: research_topic(query)["answer"],
)
For agents using the OpenAI Agents SDK or similar frameworks, Sonar can be treated as a model endpoint with native tool support disabled — letting the framework handle tool selection while Sonar handles search internally. The dual-LLM pattern (one model for reasoning and tool selection, Sonar as the search-specific endpoint) often works better than giving a general-purpose model a raw search API and hoping it queries effectively.
When Sonar Beats the Alternatives
vs. raw search API + LLM: Chaining a search API (Brave, Tavily, SerpAPI) with a separate synthesis call is more controllable but requires two API calls, prompt engineering for the synthesis step, and your own citation-linking logic. Sonar handles all three in one call. For prototyping or when search quality is good enough, Sonar is faster to ship.
vs. native LLM browsing: Claude, GPT-4o, and Gemini all offer some form of web access, but it’s opaque — you don’t control what gets searched or when. Sonar is explicit: every query you send goes to the web. That predictability matters for production agents where you need to know retrieval is happening.
vs. full RAG pipeline: If you already have a curated knowledge base, RAG over your own documents is better — you control the sources, and retrieval quality is higher for domain-specific content. Sonar is for the open web, not private knowledge.
Cost and Rate Limits
Pricing (as of mid-2026) runs roughly $5 per 1,000 requests for sonar, $15 for sonar-pro, and $30 for sonar-reasoning. Per-token costs apply on top. For agents that run dozens of searches per session, this adds up — build in a caching layer for repeated queries on the same topic within a session.
Rate limits are generous by default on paid tiers but you’ll want exponential backoff on retries. The API returns standard HTTP 429 responses.
Practical Recommendations
Use sonar for quick lookups and classification tasks. Use sonar-pro when your agent needs a thorough answer with multiple sources. Use sonar-reasoning only when the question is analytically complex — it’s noticeably slower and the cost difference matters at scale.
Set search_recency_filter deliberately. For news-dependent workflows, "day" or "week" keeps answers current. For research where older authoritative sources are fine, drop the filter entirely.
Always pass citations through to your user or downstream systems. The citation array is the source-of-truth for what was retrieved — strip it out and you’re asking users to trust an LLM answer with no way to verify it.