canonry

Perplexity Provider Design

Role

packages/provider-perplexity sends tracked queries to the Agent API (POST https://api.perplexity.ai/v1/agent). Canonry measures mentions from answer text and cited domains from the source URLs that the adapter extracts.

Perplexity retired Sonar Chat Completions on 2026-09-27 (migration guide). Rows written before the switch are Sonar responses; the adapter still parses them (see Stored history).

Model selection

The configured model is either an Agent API preset or a vendor/model slug:

Configured Request field Notes
fast (default) preset: "fast" Perplexity’s suggested replacement for sonar
low, medium, high, xhigh preset Heavier, costlier search tiers
perplexity/sonar, openai/gpt-5.1, … model One model plus Canonry’s web_search tool

Retired names still validate and resolve through PROVIDER_MODEL_ALIASES in packages/contracts/src/models.ts: sonar → fast, sonar-pro / sonar-reasoning / sonar-reasoning-pro → low, sonar-deep-research → medium. The long preset names (fast-search, pro-search, deep-research, advanced-deep-research) fold into the short ones.

Request

{
  "preset": "fast",
  "input": "best crm for startups",
  "tools": [{ "type": "web_search", "user_location": { "city": "New York", "region": "New York", "country": "US" } }],
  "tool_choice": { "type": "web_search" }
}

Response parsing

Field Source
answerText output_text parts of every message item, joined
groundingSources URLs in search_results.results, fetch_url_results.contents, and message annotations, deduplicated in output order
citedDomains Unique hosts of groundingSources
searchQueries search_results item queries[]
retrievalStatus used with a search_results or fetch_url_results item; not-used with a message and neither; unknown otherwise
servedModel Top-level model (the model a preset resolved to)
model The resolved preset or slug that was requested
usage usage: input_tokens minus the cache reads and writes input_tokens_details breaks out of it = input tokens; cache_read_input_tokens = cached; cache_creation_input_tokens = cache writes; output_tokens = output. Searches are tool_calls_details.web_search.invocation (the billed count) when reported, else one per search_results item. No usage object → none recorded
stopReason incomplete_details.reason when set, else status

The adapter reads sources from the output array and checks the response status even on HTTP 200. It accepts completed or an absent status. It accepts incomplete only with nonempty answer text. Other statuses fail the query. The shared retry policy covers rate limits, 5xx responses, and network errors.

Comparability

Switching the engine behind perplexity is treated as a model change:

Stored history

reparseStoredResult dispatches on shape. A response with an output array is Agent; anything else is Sonar Chat Completions and keeps its parser: choices[0].message.content, sources from search_results (preferred, keeps titles) or citations, no search queries, and retrievalStatus: unknown. Both work direct or wrapped under apiResponse, so canonry backfill and reparse read old sweeps as before.

Data stored per snapshot

query_snapshots.raw_response:

{
  "model": "fast",
  "groundingSources": [{ "uri": "https://example.com/page", "title": "Page Title" }],
  "searchQueries": ["best crm for startups"],
  "apiResponse": {
    "object": "response",
    "status": "completed",
    "model": "perplexity/sonar",
    "output": [
      { "type": "search_results", "queries": ["..."], "results": [{ "id": 1, "url": "...", "title": "..." }] },
      { "type": "message", "role": "assistant", "content": [{ "type": "output_text", "text": "...", "annotations": [] }] }
    ]
  }
}

Capturing fixtures

The fixtures in packages/provider-perplexity/test/fixtures/ follow the Agent API schema in Perplexity’s official SDK but are not live captures (see that folder’s README). To replace them, run each request shape with a key and save the body:

curl -sS https://api.perplexity.ai/v1/agent \
  -H "Authorization: Bearer $PERPLEXITY_API_KEY" -H 'content-type: application/json' \
  -d '{"preset":"fast","input":"best crm for startups","tools":[{"type":"web_search"}],"tool_choice":{"type":"web_search"}}' \
  > packages/provider-perplexity/test/fixtures/agent-fast-cited.json

curl -sS https://api.perplexity.ai/v1/agent \
  -H "Authorization: Bearer $PERPLEXITY_API_KEY" -H 'content-type: application/json' \
  -d '{"preset":"fast","input":"Say \"ok\""}' \
  > packages/provider-perplexity/test/fixtures/agent-no-search.json

Then update the exact values test/agent-api.test.ts asserts.

Upstream references