> ## Documentation Index
> Fetch the complete documentation index at: https://docs.perplexity.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Migrate from Sonar to the Agent API

> The Agent API represents a major upgrade of Sonar Chat Completions, bringing added configuration and powerful agentic primitives to your AI applications.

The Agent API is more performant and cost-effective for production workloads. It features Perplexity's latest innovations in search and reasoning technology, including Search as Code and tuned effort levels.

> [!NOTE]
>
> We recommend:
>
> * Migrating existing Sonar Chat Completions usage to the Agent API.
> * Using the Agent API for all new projects.

> [!NOTE]
>
> Sonar Chat Completions support ended on September 27, 2026. Synchronous and streaming requests keep working: they are being reformulated as Agent API requests, rolling out gradually by model. Asynchronous Sonar requests are not reformulated and are no longer supported; move them to [background mode](https://docs.perplexity.ai/docs/agent-api/background-mode.md).

## About the Agent API

Agent API is a unified interface for building powerful agent applications.

It contains:

* One API to call all the leading frontier and open-source models.
* Built-in tools such as [web search](https://docs.perplexity.ai/docs/agent-api/tools/web-search.md), [URL fetching](https://docs.perplexity.ai/docs/agent-api/tools/fetch-url-content.md), [sandboxes](https://docs.perplexity.ai/docs/agent-api/tools/sandbox.md), and [MCP](https://docs.perplexity.ai/docs/agent-api/tools/mcp.md), plus premium data sources like [finance](https://docs.perplexity.ai/docs/agent-api/tools/finance-search.md) and [people search](https://docs.perplexity.ai/docs/agent-api/tools/people-search.md).
* Research-backed configurations for agentic workflows, based on specific task intensity (fast, low, medium, high, xhigh — [effort levels](https://docs.perplexity.ai/docs/agent-api/effort.md)).
* Compatibility with the [Open Responses](https://www.openresponses.org/) standard to ensure portability and avoid lock-in — we want to win your business on performance and efficiency, not on locking you in with exorbitant migration costs.
* Seamless multi-turn interactions that let you [pass previous responses](https://docs.perplexity.ai/docs/agent-api/conversation-state.md#resume-from-a-prior-response) for higher-accuracy reasoning.

## Why migrate

Agent API contains several benefits over Sonar Chat Completions:

* Full flexibility to select across the OpenAI, Anthropic, Google, xAI, Z.AI, Moonshot AI, and NVIDIA model families, in addition to Perplexity's Sonar model.
* The ability to leverage multiple tools and spin up an agentic loop that reasons, acts, observes results, and continues within a single request.
* A secure [sandbox](https://docs.perplexity.ai/docs/agent-api/tools/sandbox.md) to run generated code — compute results, analyze data, and verify outputs without leaving the request.
* Connect external servers with [MCP](https://docs.perplexity.ai/docs/agent-api/tools/mcp.md) or define your own [custom functions](https://docs.perplexity.ai/docs/agent-api/tools/custom-functions.md) to extend the agent with your tools and private data.

## Sonar vs Agent API

| Capability | Sonar API | Agent API |
| - | :-: | :-: |
| Leading frontier and open-source models | | |
| Built-in web search | | |
| People Search | | |
| Finance Search | | |
| Code sandbox | | |
| MCP servers | | |
| Model fallback | | |
| Structured outputs | | |
| Streaming | | |
| Async mode | | |

Both call a model but shape the request differently.
Sonar takes a `messages` array and returns `choices`.
The Agent API takes an `input` and returns a typed `output` array — one item per step the model took, with a `message` item for the answer text and a `search_results` item for the sources.

**Sonar**

```python Python theme={null}
from perplexity import Perplexity

client = Perplexity()

completion = client.chat.completions.create(
    model="sonar",
    messages=[{"role": "user", "content": "What are the latest developments in AI agents?"}]
)
print(completion.choices[0].message.content)
```

```typescript Typescript theme={null}
import Perplexity from '@perplexity-ai/perplexity_ai';

const client = new Perplexity();

const completion = await client.chat.completions.create({
  model: 'sonar',
  messages: [{ role: 'user', content: 'What are the latest developments in AI agents?' }]
});
console.log(completion.choices[0].message.content);
```

```bash cURL theme={null}
curl https://api.perplexity.ai/v1/sonar \
  -H "Authorization: Bearer $PERPLEXITY_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "sonar",
    "messages": [
      {"role": "user", "content": "What are the latest developments in AI agents?"}
    ]
  }' | jq
```

**Agent API**

```python Python theme={null}
from perplexity import Perplexity

client = Perplexity()

response = client.responses.create(
    effort="fast",
    input="What are the latest developments in AI agents?"
)
print(response.output_text)
```

```typescript Typescript theme={null}
import Perplexity from '@perplexity-ai/perplexity_ai';

const client = new Perplexity();

const response = await client.responses.create({
  effort: 'fast',
  input: 'What are the latest developments in AI agents?'
});
console.log(response.output_text);
```

```bash cURL theme={null}
curl https://api.perplexity.ai/v1/agent \
  -H "Authorization: Bearer $PERPLEXITY_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "effort": "fast",
    "input": "What are the latest developments in AI agents?"
  }' | jq
```

> [tab] Sonar response
>
> ```json theme={null}
> {
>   "id": "8158ec84-87a8-40fd-8720-a8b8e628708c",
>   "choices": [
>     {
>       // ...
>       "message": {"content": "The latest developments in AI agents (as of July 2026) center on **massive model upgrades**, **open-source toolkits**, **real-world autonomous transactions**, and **enterprise-grade security frameworks** ...", "role": "assistant"},
>       "finish_reason": "stop"
>     }
>   ],
>   "created": 1784292153,
>   "model": "sonar",
>   "citations": [
>     "https://medium.com/@agencyai/this-weeks-ai-agent-roundup-20-launches-and-updates-you-shouldn-t-miss-401202306f62",
>     "https://www.itechmagazine.com/ai-agents-news/"
>     // ...
>   ],
>   "object": "chat.completion",
>   "search_results": [
>     {"title": "AI Agents News 2026: What's Happening Right Now and Why It ...", "url": "https://www.itechmagazine.com/ai-agents-news/", "date": "2026-06-14", "last_updated": "2026-06-21", "snippet": "Amazon Web Services open-sourced its Strands Agents SDK, a toolkit that helps developers b ...", "source": "web", "place_metadata": null}
>     // ...
>   ]
>   // ...
> }
> ```

> [tab] Agent API response
>
> ```json theme={null}
> {
>   "id": "resp_18690c07-7c56-48fa-85a3-fd22e34df694",
>   "created_at": 1784292159,
>   "model": "openai/gpt-5.6-luna",
>   "object": "response",
>   "output": [
>     {
>       "results": [
>         {"id": 1, "snippet": "This transition from one-shot intelligence to endurance, from conversational AI to genuine autonomy ...", "title": "State of AI Agents 2026: Autonomy is Here", "url": "https://www.prosus.com/news-insights/2026/state-of-ai-agents-2026-autonomy-is-here", "date": "2026-02-26", "last_updated": "2026-07-12", "source": "web"}
>         // ...
>       ],
>       "type": "search_results"
>       // ...
>     },
>     {
>       "id": "msg_525b46ea-4e33-400b-add0-6862a48549b9",
>       "content": [
>         {"text": "The latest developments in AI agents are centered on **greater autonomy, better orchestration, and stronger enterprise controls**[1][3] ...", "type": "output_text", "annotations": []}
>       ],
>       "role": "assistant",
>       "status": "completed",
>       "type": "message"
>     }
>   ],
>   "status": "completed"
>   // ...
> }
> ```

## How Sonar Chat Completions maps to Agent API effort levels

While performance improvements will vary by individual use-case, our internal benchmarks indicate performance improvements across the below comparable Sonar Chat Completions and Agent API effort level mappings.

| Sonar Chat Completions | Agent API effort level | Best for | What improves |
| - | - | - | - |
| Sonar | `fast` | Single-fact lookups, definitions, quick summaries. | More accurate than Sonar, with the clearest gains on research-style, multi-step questions. |
| Sonar Pro | `fast` | Everyday research questions, light multi-step lookups with current information. | Much more accurate, and unlocks the real multi-step, agentic research that Sonar Pro can't reach. |
| Sonar Reasoning Pro | `low` | Multi-hop browsing and wide aggregation across many sources. | Far stronger on step-by-step reasoning and on chaining evidence across several rounds of search. |
| Sonar Deep Research | `high` | Expert-level reasoning and exhaustive source coverage. | The most accurate tier on demanding expert-level and deep-research work, and often at a lower per-request cost than Sonar Deep Research. |

> [!TIP]
>
> For state-of-the-art deep research, use the `xhigh` effort level — the highest quality in the lineup, leading across the benchmarks we run.

See [Choosing an effort level](https://docs.perplexity.ai/docs/agent-api/effort.md#choosing-an-effort-level) for what each effort level is best for, and the [benchmarks page](https://docs.perplexity.ai/docs/agent-api/migrate-from-sonar/benchmarks.md) for the scores.

## Continue your migration

> [card] [How to migrate](https://docs.perplexity.ai/docs/agent-api/migrate-from-sonar/how-to.md)
>
> Follow the complete field-by-field migration procedure and parameter reference.

> [card] [Explore the effort levels](https://docs.perplexity.ai/docs/agent-api/effort.md)
>
> See what each effort level configures and how to override individual settings.
