﻿# Migrate a Sonar integration by comparing request and response shapes

Migrate a Sonar consumer by mapping messages, typed output, stream events, source identifiers, and continuation state instead of changing only the endpoint.

Author: Retrivium editorial team
Updated: 2026-11-03
Canonical URL: https://retrivium.ai/journal/guide-perplexity-sonar-agent-migration/
Language: en

A Sonar-era integration may assume messages in, one answer string out, and citations in a familiar location. The current Agent API has a richer run structure. Migration should preserve the application's useful behavior while replacing assumptions that no longer describe its request or response.

## Map the request deliberately

The [migration guide](https://docs.perplexity.ai/docs/agent-api/migrate-from-sonar/how-to) maps `messages` to `input`, with `instructions` or input items carrying standing guidance. A simple string can represent a simple turn, but flattening a conversation loses role boundaries and tool observations. Identify which parts of the old transcript the next turn actually needs.

## Replace the output parser

Answer text is available through `output_text`, while typed `output` items carry more than prose. The [compatibility guide](https://docs.perplexity.ai/docs/agent-api/openai-compatibility) explains the current surface. Branch on item type for sources and tool work. Preserve source identifiers rather than assuming their array positions reproduce the old citation numbering.

## Update streaming separately

The migration guide distinguishes legacy content deltas from typed Agent events such as `response.output_text.delta`. Tool and reasoning events are not answer fragments. An old stream concatenator can therefore display internal structures or miss the answer. Treat stream completion and the final collected result as explicit states in the consumer.

## Preserve continuation ownership

The [conversation-state guide](https://docs.perplexity.ai/docs/agent-api/conversation-state) documents replaying input or using `previous_response_id` for a completed response. Choose one intended continuation strategy and retain its identifiers. Copying only the visible final answer can discard context necessary to interpret a later question or tool result.

## Test the migrated decision paths

Use a normal grounded answer, a follow-up, and a run with non-message output. Compare supported fields and user-visible behavior rather than exact prose. The article on [deprecation migration](/journal/provider-api-contract-deprecation-migration/) explains preserving consumers. The guide to [terminal stream handling](/journal/provider-sse-terminal-eof-contract/) helps distinguish an ended connection from a completed result. Migration is complete when these paths work under the new contract, not when authentication alone succeeds.
