Skip to main content
This guide maps a Sonar chat completions integration to the Agent API. You keep the same grounded web search, and gain an agent that runs multi-step research, executes its own code, and calls tools like finance and people search.

Use the migration skill

The fastest path is to let your coding agent do the migration. Open it in the project you want to migrate and send it this:
See the repository README for supported coding agents and other installation options.

1. Update the endpoint and method

Point requests at /v1/agent and switch from chat.completions.create() to responses.create(). For plain text, the Agent API takes the same role/content items, so the body barely changes: pass the array as input instead of messages and rename the model.
Sonar
Agent API

2. Map messages to input

Sonar takes your prompt as a messages array; the Agent API takes it as input. For simple single-turn prompts, pass a plain string. To preserve a system prompt or a multi-turn transcript, pass an array of input items or use the top-level instructions field.
Sonar
Agent API
Continuing a multi-turn conversation? The shortcut is previous_response_id — point a new request at a completed prior response and skip resending the transcript. You can also replay the prior turns (including assistant items) in input yourself. See Conversation state.

3. Update output handling

Read the answer text from response.output_text — the drop-in replacement for Sonar’s choices[0].message.content. When you need more than the answer text (tool calls, search results), iterate the typed output array and branch on each item’s type.
Sonar
Agent API
The output array is a full trace, not just the answer. Beyond the final text, it records every step the model took — the searches it ran and their results, the exact code it executed in the sandbox, and any files it produced. Sonar returned only the answer and its citations; here you can inspect and audit the whole run.

Streaming

Sonar streaming returns incremental chunks with a delta.content field on each choice. The Agent API streams typed server-sent events, so update stream consumers to branch on each event’s type. For the answer text, consume response.output_text.delta events; tool calls and reasoning arrive as their own response.output_item.* and response.reasoning.* events, not as text deltas.
Sonar
Agent API
Perplexity’s own search — the grounded web search that was built into Sonar — is available through the web_search tool. In Sonar it was always on; on the Agent API you turn it on by adding web_search to the request’s tools — otherwise the model answers from its own knowledge without searching. Search controls move onto the tool too, so Sonar’s top-level search_recency_filter and search_domain_filter go into its filters. See the Web Search reference for the full set of options.
Sonar
Agent API
Web search is just one tool. Add the sandbox and the model writes and runs its own code, generating files you download from the response — and Wide Research scales that search-and-code combination to hundreds of source-backed items. See the tools overview for the full set.

Inline citations

Sonar returned inline [n] citations by default. To get the same on the Agent API, tell the model to cite the numbered web search results in its instructions:
The [n] markers are embedded directly in the answer text, not in a separate field. The sources they point to come back separately in an output item with type: "search_results" — read them from its results, each carrying an id, and each [n] marker maps to the result whose id is n.
More than search — the Agent API is agentic. The model runs a loop, so you can hand it a task and let it work through the steps itself. In addition to web search, it can call tools like Finance Search for structured market and filing data and People Search for professional profiles.

5. Map Sonar models to presets

Starting points we suggest: sonarfast, sonar-prolow, sonar-reasoning-promedium, sonar-deep-researchhigh. See Presets for details.
Sonar
Agent API
Need more than Sonar could do? Use the higher tiers. high does deep research across many sources — good for detailed analysis and reports. xhigh adds a code sandbox and runs longer tool-use loops, so it can handle open-ended tasks that a single query can’t.

6. Migrate async requests (optional)

Sonar’s async API maps to Agent API background runs: submit with background: true and poll the response by id. See Background Runs for the request shape, polling, reconnect, and the full lifecycle.

Parameter reference

Map the common Sonar parameters to their Agent API equivalents. Some are direct field moves; others are the closest Agent API pattern, and those rows call out the missing 1:1 equivalent.
Missing a Sonar behavior you rely on? Tell us at api@perplexity.ai — it helps us prioritize what lands on the Agent API next.

Standard OpenAI parameters

These standard OpenAI parameters carry over unchanged: temperature, top_p, and stream. A couple of parameters change on the Agent API:
  • max_tokens is renamed to max_output_tokens.
  • response_format keeps the same shape for json_schema, and structured outputs are not restricted to specific Perplexity models on the Agent API. Sonar’s response_format.type: "regex" has no Agent API equivalent — redesign regex flows around a JSON schema.

Sonar-specific parameters

Direct equivalents (some renamed or relocated): No direct field — map to a tool or pattern: No Agent API equivalent — drop these:
  • search_language_filter.
  • stream_mode — Agent API streaming always emits typed SSE events with reasoning and tool activity as separate events, closest to Sonar’s concise mode; there is no full-mode inline-metadata format.
  • Image results (return_images, num_images, image_domain_filter, image_format_filter, web_search_options.image_results_enhanced_relevance) — not supported; the Agent API returns no images.
  • Video results (return_videos, num_videos, media_response) — not supported; the Agent API returns no videos.
See the Web Search reference for the full set of web_search options.

Multimodal input