> For the complete documentation index, see [llms.txt](https://docs.scraperapi.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.scraperapi.com/structured-data-endpoints/ai-results/perplexity.md).

# Perplexity

The `Perplexity Search API` endpoint fetches response data from a results page of a Perplexity prompt. Results can be returned in raw HTML format or as a structured JSON format.

{% tabs %}
{% tab title="cURL" %}

```bash
curl --request GET \
--url "https://api.scraperapi.com/structured/perplexity/search/v1?api_key=API_KEY&\
query=QUERY&output_format=OUTPUT_FORMAT&include_html=Boolean"
```

{% endtab %}

{% tab title="Python" %}

```python
import requests

payload = {
    'api_key': 'API_KEY',
    'query': 'QUERY',
    'output_format': 'OUTPUT_FORMAT',
    'include_html': 'Boolean' #True/False
}

r = requests.get('https://api.scraperapi.com/structured/perplexity/search/v1',params=payload)

print(r.text)
```

{% endtab %}

{% tab title="NodeJS" %}

```javascript
import fetch from 'node-fetch';

fetch(
  'https://api.scraperapi.com/structured/perplexity/search/v1?api_key=API_KEY&query=QUERY&output_format=OUTPUT_FORMAT&include_html=Boolean'
)
  .then(response => response.json()) 
  .then(data => {
    console.log(data);
  })
  .catch(error => {
    console.error(error);
  });
```

{% endtab %}

{% tab title="PHP" %}

```php
<?php
$url = "https://api.scraperapi.com/structured/perplexity/search/v1?api_key=API_KEY&query=QUERY&output_format=OUTPUT_FORMAT&include_html=Boolean";

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_HEADER, FALSE);

$response = curl_exec($ch);
curl_close($ch);

print_r($response);
```

{% endtab %}

{% tab title="Ruby" %}

```ruby
require 'net/http'
require 'json'

params = {
  :api_key => "API_KEY",
  :query => "QUERY",
  :output_format => "OUTPUT_FORMAT",
  :include_html => "Boolean" #True/False
}

uri = URI('https://api.scraperapi.com/structured/perplexity/search/v1')
uri.query = URI.encode_www_form(params)

website_content = Net::HTTP.get(uri)
print(website_content)
```

{% endtab %}

{% tab title="Java" %}

```java
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;

public class Main {
    public static void main(String[] args) {
        try {
            String apiKey = "API_KEY";
            String query = "QUERY";
            String output_format = "output_format";
            String include_html = "Boolean"; // True/False

            String urlStr = "https://api.scraperapi.com/structured/perplexity/search/v1?api_key=" 
                            + apiKey + "&query=" + query + "&coutput_format=" + output_format + "&include_html=" + include_html;

            URL url = new URL(urlStr);
            HttpURLConnection conn = (HttpURLConnection) url.openConnection();
            conn.setRequestMethod("GET");

            int responseCode = conn.getResponseCode();
            if (responseCode == HttpURLConnection.HTTP_OK) {
                BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream()));
                StringBuilder response = new StringBuilder();
                String line;
                while ((line = in.readLine()) != null) {
                    response.append(line);
                }
                in.close();
                System.out.println(response.toString());
            } else {
                System.out.println("Error in API Call. Response code: " + responseCode);
            }

        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
}
```

{% endtab %}
{% endtabs %}

**Supported Parameters**

<table><thead><tr><th width="274.2591552734375">Parameters</th><th>Details</th></tr></thead><tbody><tr><td><code>API_KEY</code> (required)</td><td>Your API Key.</td></tr><tr><td><code>QUERY</code> (required)</td><td>The prompt to send to Perplexity.</td></tr><tr><td><code>OUTPUT_FORMAT</code></td><td><code>json</code> returns parsed structured data (default). <code>html</code> returns raw HTML.</td></tr><tr><td><code>INCLUDE_HTML</code></td><td>Determines whether raw HTML is included in the response (this can increase the size of the response). Can be set to true or false (default).</td></tr></tbody></table>

**JSON Response**

```json
{
  "query": "string",              // the submitted prompt, echoed back
  "url": "string|null",           // result/thread URL for the answer
  "model": "string|null",         // model that produced the answer (see notes)
  "answer": "string",             // the full answer, in Markdown
  "sources": [                    // citations / web results (may be empty)
    {
      "title": "string",
      "url": "string",
      "domain": "string",         // bare hostname, www. stripped
      "snippet": "string"         // may be empty when the engine gives none
    }
  ],
  "related_queries": ["string"]   // follow-up suggestions (may be empty)
}
```

**Field Reference**

<table data-search="false"><thead><tr><th width="172.8887939453125">Field</th><th width="165.1480712890625">Type</th><th width="177.5555419921875">Always present?</th><th>Notes</th></tr></thead><tbody><tr><td><code>query</code></td><td>string</td><td>yes</td><td>Echoed prompt</td></tr><tr><td><code>url</code></td><td>string | null</td><td>yes</td><td>Result/thread URL</td></tr><tr><td><code>model</code></td><td>string | null</td><td>yes</td><td>Best-effort. <code>null</code> when not surfaced</td></tr><tr><td><code>answer</code></td><td>string (Markdown)</td><td>yes</td><td>The answer body</td></tr><tr><td><code>sources[]</code></td><td>array of object</td><td>yes (may be empty)</td><td><code>{ title, url, domain, snippet }</code></td></tr><tr><td><code>related_queries[]</code></td><td>array of string</td><td>yes (may be empty)</td><td>Follow-up suggestions</td></tr></tbody></table>

{% hint style="success" %}
All fields are always present in the JSON (empty array or `null` rather than omitted).
{% endhint %}

#### Specifics

**`model`**

* **Populated** for Perplexity. For example  `turbo`.

**`sources`**

* Present in the response.
* **snippet**
* **domain** is normalized to a bare hostname (**[www](http://www).** stripped) across all engines.

**`related_queries`**

* Present in the response (may be empty).

**Example**

```json
{
  "query": "where to visit in Italy",
  "url": "https://www.perplexity.ai/search/6341fc7a-b727-4a08-8e66-49cbeef35407",
  "model": "turbo",
  "answer": "Italy offers a mix of history, cuisine, and scenery. Here are the must-see regions...\n\n- **Rome** ...\n- **Florence** ...",
  "sources": [
    {
      "title": "Best Places To Visit In Italy For The First Time",
      "url": "https://earthtrekkers.com/best-places-to-visit-in-italy/",
      "domain": "earthtrekkers.com",
      "snippet": "Some destinations stand out more than the rest..."
    }
  ],
  "related_queries": [
    "Best time of year to visit Italy",
    "How many days do you need in Italy"
  ]
}
```

#### Pricing

Perplexity queries run on ScraperAPI's standard credit system.

| **Request Type** | **Credits Charged** |
| ---------------- | ------------------- |
| `Any Parameter`  | 25                  |


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.scraperapi.com/structured-data-endpoints/ai-results/perplexity.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
