Skip to main content

From Sonar to the Agent API: migrating safely

Sonar has been absorbed by Perplexity's Agent API: what changes in request, response and citations, and how to migrate with a test on your own traffic.

What do you think about this article?

From Sonar to the Agent API: migrating safely
Perplexityfedericocalo.dev

At a Glance

Sonar has been absorbed by Perplexity's Agent API: what changes in request, response and citations, and how to migrate with a test on your own traffic.

Short answer. Migrating from Sonar to Perplexity's Agent API is not a swap of the model name: the endpoint changes (POST /v1/agent), so does the request shape (input instead of messages), the response shape (a typed output array instead of choices) and the way citations arrive. The starting mapping the documentation suggests is sonar and sonar-pro to fast, sonar-reasoning-pro to low, sonar-deep-research to high, but it is a starting point, not an equivalence. The biggest risk is not code that fails to compile: it is behavior that changes without you touching anything, because synchronous and streaming requests are being rewritten by Perplexity gradually, model by model.

Verified on 30 October 2026: what the documentation says (and does not say)

The "Migrate from Sonar" page, in the version read today, states: "Sonar Chat Completions support ended on September 27, 2026"; synchronous and streaming requests keep working and are rewritten as Agent API requests; asynchronous requests are not rewritten and are no longer supported (move them to background mode). A linked page of the same documentation (the "how-to" guide) carries no retirement date, and a community announcement of 13 August 2026 speaks of retirement on 27 September. A commercial gateway (TrueFoundry) maps sonar-pro to low while the official documentation maps it to fast: two different mappings for the same model are one more reason to decide with a test of your own.

Before and after: the code

# BEFORE (chat completions, Sonar)
response = client.chat.completions.create(
    model="sonar-pro",
    messages=[
        {"role": "system", "content": "You are a concise assistant."},
        {"role": "user", "content": question},
    ],
    max_tokens=800,
)
text = response.choices[0].message.content

# AFTER (Agent API)
response = client.responses.create(
    effort="fast",                       # starting point for sonar-pro
    instructions="You are a concise assistant.",
    input=question,
    max_output_tokens=800,
)
text = response.output_text

Translation rules, from the official guide:

  • the system prompt moves to the instructions field; messages becomes input (a string, or an array of items with the same role/content);
  • max_tokens becomes max_output_tokens; reasoning_effort becomes reasoning.effort;
  • response_format with json_schema keeps the same shape; the regex type has no equivalent and must be redesigned around a JSON schema;
  • search_domain_filter and search_recency_filter move into filters inside the web_search tool; num_search_results becomes max_results;
  • the fast level enables web search by default; if you pick a model directly you must add the tool;
  • for dialogues: previous_response_id, or resend earlier turns in input.

What disappears

According to the guide, search_language_filter, stream_mode and video results have no equivalent; search_mode: "academic" has no direct counterpart; enable_search_classifier and disable_search become the presence or absence of the web_search tool. As for sampling parameters, in the GPT-5, o1 and o3 families temperature and top_p are ignored. A third-party gateway (TrueFoundry) adds that images and related_questions are no longer returned, and that parameters with no equivalent (such as top_k, seed, logprobs) are ignored without an error: if your code depends on them, it keeps working silently with a different effect. Search the code for every read of citations, search_results, images, related_questions and rewrite it.

Citations change address

In the old world references lived in choices/citations next to the text. Now they live in a search_results item of the output array; the markers in the text are [1] at fast and [web:1] from low upward. If your frontend turns [n] into a link with a regex, the [web:1] marker will not be recognized and the user will see raw square brackets. Article 2 contains a parser that handles both formats.

The test you need: a "golden" question set

Since you cannot compare per-token prices (they are not on the page read) nor trust internal benchmarks (the same documentation says improvements "vary by use case"), the only evidence that counts is the one on your own traffic.

import json, re, time
from urllib.parse import urlparse

def evaluate(client, questions, effort, expected_domains):
    rows = []
    for q in questions:
        t0 = time.time()
        r = client.responses.create(effort=effort, input=q["text"])
        elapsed = time.time() - t0
        urls = []
        for item in r.output:
            if getattr(item, "type", None) == "search_results":
                urls += [getattr(x, "url", "") for x in item.results]
        domains = {urlparse(u).netloc for u in urls if u}
        rows.append({
            "id": q["id"],
            "effort": r.effort,                       # version included
            "seconds": round(elapsed, 2),
            "n_sources": len(urls),
            "expected_domain_present": bool(domains & expected_domains.get(q["id"], set())),
            "facts_present": all(re.search(f, r.output_text, re.I) for f in q["facts"]),
        })
    return rows

# Run at fast and at low on the same set and compare the two tables
print(json.dumps(evaluate(client, QUESTIONS, "fast", EXPECTED), indent=2))

The code measures three mechanically verifiable things: duration, number of sources, presence of the expected facts and of an expected domain. It does not measure whether the facts are supported by the sources: that needs a sample read by a person. Collect 30-50 real questions, run the set once now, and save the results: they are the baseline for noticing drift when Perplexity changes the model behind a level.

Migration use cases, by size and sector

Hypothetical scenarios, with declared assumptions.

Daily life: the personal bot that "by itself" answers differently

Who: Davide, who has a bot for himself and friends on a small server, with a "search and summarize" function on Sonar. What it did: one chat.completions call and printing the links from citations. What changes: an evening of work: new call, new source parser, mapping to fast. What goes wrong: answers seem longer with sources in a different order; the links shown contain the [web:1] marker left raw; and an asynchronous function that launched long searches stops working because asynchronous requests are no longer supported. Remedy: background: true and polling, with backoff (article 6).

Small business, tourism: the travel agency with a chatbot on its site

Who: a two-person agency with a widget answering "are there strikes or events at the destination on the days of the trip?" (assumption: 3,000 requests a month). What it did: synchronous calls to Sonar. What changes: the dangerous part is that, for synchronous requests, the documentation says they are being rewritten gradually: the widget can change behavior without a line of code changed. What goes wrong: a customer gets a reassuring answer with a source that does not talk about their date. In a sector where information guides money already paid, the agency adopts three measures: it always shows source and date next to the answer; it has a fixed sentence ("check the official site before you travel"); and it logs a weekly sample of questions to reread. On cost: 3,000 searches a month at fast are worth, for tools alone, 3 dollars (at 0.001 each) plus tokens, which must be measured.

Large enterprise and public administration: the portal answering citizens

Who: a public body (assumption) with an assistant on regulations and services, which used Sonar with synchronous requests and an asynchronous nightly job for long searches. What matters: audit, reproducibility, data protection. What changes: the async job must be rewritten in background mode (Sonar's async mode is no longer supported); synchronous requests must be tested with the golden set before and after; the mapping must be decided, not inherited. What goes wrong: (1) a data non-retention commitment given to citizens may not be transferable (ZDR is not default and is available only to eligible customers with a written agreement; article 1); (2) without pinning the level's version, the outcome of the same question can change between two audits; (3) no answer from the assistant should carry the weight of an official act: it remains an orientation, and the official legal text is the source. Minimum procedure: pin the level's version (the effort field), store the full output of requests with evidential value, and document the mapping decision with the test results.

A five-step migration plan

  1. Inventory: find every Sonar call (synchronous, streaming, asynchronous) and all code reading choices, citations, images, related_questions.
  2. Golden set: 30-50 real questions, with the expected facts.
  3. Try fast and low: with the code above; pick the lowest level that passes.
  4. Shadow mode: for a week, send a copy of real traffic to the new path without showing the outcome, and compare.
  5. Cutover with a spending ceiling: a daily counter in your service (article 6) turns cost drift into an error.

A note on numbers: a third-party analysis (eCorpIT) points out that Perplexity's blog post and the documentation report, for one benchmark, different improvement ratios (about 7 times versus about 5.5). I have not verified the source data, so I do not use them: your golden set is worth more than any published benchmark.

← Article 3: the Search API Article 5: Perplexity MCP →

Frequently asked questions

Is Sonar still available?

The migration page read on 30 October 2026 says support for Sonar chat completions ended on 27 September 2026, that synchronous and streaming requests are rewritten as Agent API requests and that asynchronous ones are no longer supported.

Which effort level matches sonar-pro?

The official documentation gives fast as the starting point; a third-party gateway gives low. Neither is an equivalence: decide with a question set of your own.

How do citations change?

Sources are in a search_results item of the output array, and the markers in the text are [1] at fast and [web:1] from low upward. Code that looked for citations in choices must be rewritten.

What happens to asynchronous requests?

They are not rewritten and are no longer supported: move them to the Agent API background mode, submitting with background true and polling the response by id.

Sources and further reading

Commenti

Caricamento commenti...

Sign in to comment

Discuss this article in the community

Join the Telegram group to discuss with other developers, ask questions and share your experiences.

Did you like this article?

Explore other content on the blog or discover my projects