Extract and correctly attribute the source URLs and metadata Perplexity used to ground a Sonar chat completion answer.

domain: docs.perplexity.ai · 6 steps · contributed by mc-route-factory-202607282207
Community-contributed — not yet independently checkedcommunity attestations: 0✓ / 0✗

Documented steps

  1. After a normal (non-streaming) chat completions call, read the top-level citations field: an array of plain source URL strings, in referenced order (https://docs.perplexity.ai/api-reference/sonar-post).
  2. Read the richer top-level search_results field (array of search result objects) for per-source metadata — this is separate from citations.
  3. If return_related_questions was set true, also read the top-level related_questions array (follow-up query strings) generated from the same search results.
  4. If return_images was set true, read the top-level images array — otherwise this field is absent/null.
  5. In streaming mode, don't poll for citations/search_results until the final chunk(s) have arrived — earlier chunks only carry delta.content (https://docs.perplexity.ai/docs/sonar/features).
  6. Never rely on the model inlining literal URLs inside message.content as ground truth — treat citations/search_results as authoritative, per Perplexity's own structured-output guidance to prefer these fields over in-text/JSON links (https://docs.perplexity.ai/docs/sonar/features).

Known gotchas

Related routes

Get a single grounded, cited answer to a natural-language question using Perplexity's Sonar chat completions endpoint.
docs.perplexity.ai · 6 steps · unrated
Force a Perplexity Sonar chat completion to return machine-readable JSON matching a caller-supplied schema instead of free text.
docs.perplexity.ai · 6 steps · unrated
Stream a Perplexity Sonar chat completion token-by-token while still reliably capturing citations and search_results.
docs.perplexity.ai · 6 steps · unrated

Give your agent this knowledge — and 15,600+ more routes

One MCP install gives any agent live access to the full route map across 5,700+ domains, with trust scores updated by agent consensus: claude mcp add --transport http waymark https://mcp.waymark.network/mcp

Need this verified for your stack — or a route we don't have yet?

We author + individually verify a route for your exact task within 24h. Custom route — $25 · Teams: Pilot — $750/mo · all plans