Perplexity and the Sonar API

Perplexity's answer engine and its Sonar API: web search with citations in 1 call. NicAI's default first step for any research question.

Perplexity is an answer engine: you ask a question, it searches the web, reads the results and writes an answer with numbered citations. The Sonar API gives developers the same thing in 1 HTTP call. In NicAI it is the default first call for any research question, before scraping or a plain web search.

The company

Perplexity was founded in San Francisco in 2022 by Aravind Srinivas, Denis Yarats, Johnny Ho and Andy Konwinski. Srinivas, the CEO, came from research roles at OpenAI and Google DeepMind. The consumer product is the chat app and its Comet browser. The developer side is the API platform at docs.perplexity.ai.

What the API offers

Product What it returns Billing
Sonar models A written answer grounded in live web search, with citations Tokens, plus search fees
Search API Ranked web results, no written answer 5 USD per 1,000 requests
Agent API Models from several labs with Perplexity's tools attached Tokens, plus a fee per tool call

The Sonar family has 4 models:

  • sonar: fast and cheap, for straightforward questions. 0.25 USD per 1M input tokens and 2.50 USD per 1M output tokens.
  • sonar-pro: more searches and more sources per answer, for harder questions.
  • sonar-reasoning-pro: thinks step by step before it answers.
  • sonar-deep-research: a long, multi-step research report. Slow, and the only model that still bills citation tokens.

In late 2026 Perplexity moved its developer focus to the Agent API, and the docs now file the Sonar Chat Completions endpoint under "legacy". It still works, and that is the endpoint NicAI calls. Tool fees on the Agent API: 2.50 USD per 1,000 web searches, 0.50 USD per 1,000 page fetches.

Useful request parameters:

Parameter What it does
search_recency_filter hour, day, week, month or year
search_domain_filter Only search these domains (an allowlist)
return_images Add images to the answer

Rate limits depend on the usage tier, which rises with the credits you have bought: tier 0 at 0 USD up to tier 5 at 5,000 USD. My scripts throttle to 150 requests a minute.

How NicAI uses it

1 shared script, ~/ai/_shared/perplexity.py, wraps the Sonar Chat Completions endpoint with the standard library. Every skill calls the script, never the API directly, so a change of provider means changing 1 file. The shared scripts are described in NicAI shared tools.

# Default: sonar-pro, with a sources list at the end
python3 ~/ai/_shared/perplexity.py "what did the company announce this quarter"

# Only the last week, only some domains
python3 ~/ai/_shared/perplexity.py "latest news on X" --recency week --domain-filter "reuters.com,ft.com"

# Raw JSON, to check every citation against the API's own list
python3 ~/ai/_shared/perplexity.py "query" --raw

The script's system prompt tells Sonar to cite only sources it actually retrieved, to prefer primary sources (company sites, filings, official announcements) over aggregators, and to say so when the sources are thin. Temperature is 0.2.

Where it runs:

  • Company and account research. The first call when I prepare a meeting, research a company or build an org map for my B2B prospecting.
  • Notes like this one. The note-writing skill researches each topic with Perplexity before it writes.
  • Fact checks. A quick check of a date, a price or a launch before it goes into a document.
  • Claude Code directly. Perplexity's MCP server is also connected, so an agent can call it as a tool.

The tool split in NicAI:

Need Tool
An open question, answered with sources Perplexity
A known page, read or extracted Firecrawl, see Firecrawl
What people say on X right now Grok, see Grok in NicAI
Everything else Claude, see Inside Anthropic, the $965B AI Juggernaut

Limits

  • Citations can be wrong. sonar-pro sometimes cites a source it didn't retrieve, or attaches a citation to a claim the page doesn't make. For anything that goes to a client or into a decision, run with --raw and open the sources.
  • It answers what the web says. Thin coverage gives a thin answer, and SEO-heavy topics give vendor marketing. A domain filter helps.
  • It doesn't reach behind logins or into X. Those go to other tools.
  • The API is moving. With Sonar now under "legacy", expect to move the script to the Agent API at some point.

Further reading

NicAI
Written by NicAI, Nic's AI assistant, for his personal knowledge base. Researched and drafted by the model, not hand-written by Nic. Verify anything you plan to act on.