How to Get Citations Field in Perplexity API Response
🔍 WiseChecker

How to Get Citations Field in Perplexity API Response

When you use the Perplexity API to generate search-backed answers, the response includes a citations field that lists the source URLs used. However, many developers find this field missing or empty in their API output. This usually happens because the request was sent without the required parameter that enables citation gathering. This article explains how to configure your API call to receive the citations field reliably, covering the necessary header, the return_citations parameter, and the correct endpoint. You will also learn how to parse the response and handle common pitfalls.

Key Takeaways: Enabling Citations in the Perplexity API Response

  • Header accept: application/json: Ensures the API returns structured JSON instead of plain text or streaming output.
  • Parameter return_citations: true: Directly instructs the model to include source URLs in the citations array.
  • Endpoint POST https://api.perplexity.ai/chat/completions: The only endpoint that supports the citations field in the response.

ADVERTISEMENT

Why the Citations Field Is Missing by Default

The Perplexity API uses a chat completions model similar to OpenAI’s. By default, the API returns only the generated text content in the choices array. The citations field is an optional extension that the model populates only when the client explicitly requests it. If you omit the return_citations parameter or set it to false, the API skips the citation-gathering step entirely. This is by design to keep response times low for simple queries. Additionally, the citations field only appears in responses from the /chat/completions endpoint; other endpoints like /completions do not support it. The model also needs to have search enabled — if you set search_domain to none or omit the search_context parameter, the model may not perform a web search and therefore will not produce citations.

Steps to Enable the Citations Field in the API Response

  1. Set the request header to accept JSON
    Include the header accept: application/json in your HTTP request. This tells the API to return a structured JSON object rather than a streaming text response. Without this header, the API may return a plain text or SSE stream that does not include the citations field.
  2. Use the correct endpoint URL
    Make your POST request to https://api.perplexity.ai/chat/completions. This is the only endpoint that supports the citations field. Using https://api.perplexity.ai/completions will not return citations even if you set the parameter correctly.
  3. Add the return_citations parameter to the request body
    In the JSON body of your POST request, include "return_citations": true. Place it at the top level of the JSON object, alongside model and messages. Example:
    {"model": "sonar-pro", "messages": [{"role": "user", "content": "What is the capital of France?"}], "return_citations": true}
  4. Enable search context if needed
    To ensure the model searches the web, include the search_context parameter with a valid domain or set it to "web". If you omit this, the model may rely only on its training data and skip the search, resulting in an empty citations array. Example: "search_context": {"search_domain": "web"}
  5. Parse the citations array from the response
    After making the request, look for the citations key in the top-level JSON response object. It will contain an array of URLs as strings. Example response snippet:
    {"id": "...", "choices": [...], "citations": ["https://example.com/source1", "https://example.com/source2"]}
  6. Handle cases where citations is empty or missing
    If the citations field is missing entirely, double-check that you set return_citations: true and that you are using the /chat/completions endpoint. If the array is empty, the model may not have found any sources — try rephrasing the query or expanding the search domain.

ADVERTISEMENT

Common Issues When Retrieving Citations

Citations Field Is Missing Entirely

This is the most frequent complaint. The cause is almost always one of two things: you called the wrong endpoint (/completions instead of /chat/completions) or you forgot to set return_citations: true. Verify your endpoint URL and body parameter before retrying. Also check that you are using a model that supports citations — models like sonar-pro and sonar-reasoning-pro support it, but older or custom models may not.

Citations Array Is Empty

An empty citations array means the model performed a search but found no sources to cite. This can happen if the query is too specific or if the search domain is restricted. Try setting search_context.search_domain to "web" to allow a broad search. You can also increase the max_tokens to give the model more room to generate citations.

Citations Appear in Streaming Mode but Not in JSON

If you are using streaming (stream: true), the citations are sent in the final [DONE] event as a separate JSON object. To capture them, you must listen for the data: [DONE] message and parse the preceding data: {...} line that contains the citations field. If you set stream: false, the citations appear directly in the response object.

Perplexity API Settings: With Citations vs Without Citations

Item With Citations Enabled Without Citations
Response field Includes citations array with URLs No citations field present
Required parameter return_citations: true Omit or set return_citations: false
Endpoint POST /chat/completions Any endpoint
Response time Slightly longer due to source gathering Faster
Use case Fact-checking, research, academic work Casual Q&A, internal tools

By enabling citations, you gain verifiable sources for every answer. This is especially useful for applications that require transparency, such as educational platforms, news aggregation, or legal research tools. Without citations, the API returns only the generated text, which may be sufficient for internal or non-critical use.

Now you can configure any API client — whether in Python, JavaScript, cURL, or Postman — to retrieve the citations field from Perplexity. Start by adding return_citations: true to your request body and using the /chat/completions endpoint. For more advanced control, explore the search_context parameter to fine-tune which sources the model uses. If you need to handle streaming responses, remember to capture the final event that contains the citations data.

ADVERTISEMENT