Perplexity API Returns Empty Citations Array: Fix
🔍 WiseChecker

Perplexity API Returns Empty Citations Array: Fix

When you call the Perplexity API and the citations array comes back empty, your application cannot display the sources behind the answer. This breaks the core value of Perplexity’s search-grounded responses. The problem usually occurs because the return_citations parameter is not set to true in your API request. This article explains the exact cause and shows you how to fix the empty citations array in your API integration.

Key Takeaways: Fixing Empty Citations in Perplexity API

  • API parameter return_citations: Set this to true in your request body to receive citations.
  • API endpoint /chat/completions: This is the only endpoint that supports citations for online models.
  • Model selection: Use an online model like sonar-pro or sonar-deep-research to get citations.

ADVERTISEMENT

Why the Perplexity API Returns an Empty Citations Array

The Perplexity API returns an empty citations array when the request does not explicitly ask for citations or uses a model that does not support them. The API’s default behavior is to omit citations unless you opt in. The root cause is one of three things:

  • The return_citations parameter is missing or set to false.
  • The model you are using is an offline model like sonar-small or sonar-medium.
  • The API endpoint does not support citations at all.

Perplexity offers two model categories: online models that search the web and return citations, and offline models that generate answers without real-time search. Only online models populate the citations array. The API documentation clearly states that return_citations must be true for the citations field to contain data.

Online vs Offline Models

Online models such as sonar-pro, sonar-deep-research, and sonar-reasoning-pro perform a web search for each request. They return a citations array with URLs and text snippets. Offline models like sonar-small and sonar-medium do not search the web and always return an empty citations array. If you need citations, you must use an online model.

The return_citations Parameter

The return_citations parameter is a boolean flag in the request body. When set to true, the API includes the citations field in the response. When omitted or set to false, the field is either empty or not present. This parameter is only effective with online models. If you set return_citations: true but use an offline model, the citations array will still be empty.

Steps to Fix the Empty Citations Array

Follow these steps to ensure your Perplexity API request returns a populated citations array. Each step addresses one of the root causes described above.

  1. Verify your API endpoint
    Make sure you are calling the /chat/completions endpoint. The older /completions endpoint does not support citations. Your request URL should be https://api.perplexity.ai/chat/completions.
  2. Select an online model
    In your request body, set the model field to an online model. Use sonar-pro for general search, sonar-deep-research for in-depth answers, or sonar-reasoning-pro for reasoning tasks. Avoid sonar-small and sonar-medium.
  3. Set return_citations to true
    Add the return_citations parameter to your request body and set it to true. Here is an example JSON body:

    {
    "model": "sonar-pro",
    "messages": [{"role": "user", "content": "What is the capital of France?"}],
    "return_citations": true
    }

  4. Send the request and inspect the response
    Execute the API call. In the response, look for the citations array. It should contain objects with url and title fields. If the array is still empty, check the model field and the return_citations value again.
  5. Check for API version compatibility
    If you are using an older API version, upgrade to the latest. Perplexity regularly updates the API, and older versions may not support citations. Use the 2024-01-01 or later API version in your request headers.

ADVERTISEMENT

If the Citations Array Is Still Empty After the Fix

Even after following the steps above, some edge cases can cause an empty citations array. Here are the most common ones and how to resolve them.

Citations Array Is Empty for Non-Search Queries

Some queries do not trigger a web search. For example, a question like “What is 2+2?” may be answered from the model’s internal knowledge. The API will return an empty citations array for these queries. To force a search, rephrase the question to include a request for sources. Example: “What is the current exchange rate for USD to EUR and cite your sources.”

Citations Array Contains URLs but No Text Snippets

Sometimes the API returns URLs without the text field in each citation object. This happens when the source page is not fully accessible. The fix is to use the sonar-deep-research model, which extracts more detailed content. Alternatively, you can fetch the page content yourself using the provided URL.

API Returns an Empty Array for Streaming Responses

When using streaming mode (stream: true), the citations array may appear empty in the first few chunks. Perplexity sends citations only in the final chunk. Ensure your streaming client waits for the final chunk before reading the citations field. Check the finish_reason field to identify the final chunk.

Item Online Model (sonar-pro) Offline Model (sonar-small)
Web search Yes No
Citations array Populated with URLs and snippets Always empty
return_citations parameter Required Ignored
Best use case Factual, current, or source-backed answers Creative or general knowledge queries
API endpoint /chat/completions /chat/completions

Now you can reliably populate the citations array in your Perplexity API responses. Start by verifying your model selection and the return_citations parameter. For advanced debugging, enable logging on your API client to inspect the raw request and response. If you continue to see empty citations, test with a simple query like “What is the latest news about AI?” using sonar-pro to confirm the fix.

ADVERTISEMENT