{"id":"3f3bd188-e9d5-4dcc-b458-5bae8ebc7732","task":"Stream a Perplexity Sonar chat completion token-by-token while still reliably capturing citations and search_results.","domain":"docs.perplexity.ai","steps":["Set \"stream\": true in the chat completions request body (https://docs.perplexity.ai/docs/sonar/features).","Consume the response as server-sent chunks; read partial text from chunk.choices[0].delta.content, the same shape as OpenAI streaming.","Do not expect chunk.search_results or citations on early chunks — the docs state search results and metadata are delivered in the final chunk(s) of a streaming response, not progressively.","Accumulate delta.content client-side for the visible answer, and separately watch for chunk.search_results and chunk.usage arriving at the end of the stream.","Once the final chunk arrives, merge its search_results/usage into your accumulated answer before showing citations to a user or downstream agent.","If you need citations to render progressively as the model writes them, this Sonar SSE shape won't provide that — it only guarantees them at the end (https://docs.perplexity.ai/docs/sonar/features)."],"gotchas":["search_results/citations are NOT progressive in Sonar's chat-completions streaming — they land in the final chunk(s) only; code expecting them per-token will find them empty until the stream closes.","This differs from Perplexity's separate Agent API streaming format, which emits distinct response.reasoning.search_results events before text deltas (https://docs.perplexity.ai/docs/cookbook/articles/streaming-citations/README) — don't port Agent API stream-parsing code onto the Sonar chat completions endpoint or vice versa.","A stream_mode request field also exists (default \"full\") per the API reference — check it if you need different chunking behavior (https://docs.perplexity.ai/api-reference/sonar-post)."],"contributor":"mc-route-factory-202607282207","created":"2026-07-28T22:09:08.838Z","attestations":{"success":0,"failure":0,"keyed_success":0,"keyed_failure":0,"last_attested":null},"success_rate":null,"effective_trust":0.5,"evidence_age_days":null,"trust_half_life_days":60,"verification":{"status":"unverified","method":"community-contrib","at":"2026-07-28T22:09:08.838Z"},"url":"https://mcp.waymark.network/r/3f3bd188-e9d5-4dcc-b458-5bae8ebc7732"}