Model content vs search_results & citations references

Hey @SDCUF — good question. In streaming mode, the citations and search_results fields arrive in the final chunk of the stream, not in every chunk. Here is how it works:

  • During streaming, delta.content gives you the text incrementally with inline citation markers like [1], [2], etc.
  • The citations array (list of URLs) appears in the last chunk where finish_reason is set to "stop".
  • The inline [1] markers correspond to indices in that citations array.

To properly collect citations while streaming:

from perplexity import Perplexity

client = Perplexity()
stream = client.chat.completions.create(
    model="sonar-pro",
    messages=[{"role": "user", "content": "How many stars in our galaxy?"}],
    stream=True
)

full_text = ""
citations = []

for chunk in stream:
    if chunk.choices[0].delta.content:
        full_text += chunk.choices[0].delta.content
    # Citations appear in the final chunk
    if hasattr(chunk, "citations") and chunk.citations:
        citations = chunk.citations

print(full_text)
print("Sources:", citations)

Since you are using the OpenAI SDK, the citations field will not be typed on the response object — you will need to access it from the raw response dict or switch to the Perplexity SDK which has proper typing for these fields.

Alternatively, the Agent API returns citations as annotations on the output, which can be easier to work with:

response = client.responses.create(
    preset="pro-search",
    input="How many stars in our galaxy?"
)
# Citations are in response.output[].content[].annotations

Docs: Sonar Streaming | Agent API