> For the complete documentation index, see [llms.txt](https://developers.oxylabs.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://developers.oxylabs.io/api-targets/llms-and-ai/perplexity.md).

# Perplexity

The `perplexity` source lets you submit a prompt and receive a fully parsed, structured response, including the formatted answer, web sources used, related queries, and displayed UI tabs. Product-related prompts can return shopping results and inline product listings.

## Request samples

The code examples below illustrate how to send prompts to Perplexity and retrieve parsed responses.

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

```bash
curl 'https://realtime.oxylabs.io/v1/queries' \
--user 'USERNAME:PASSWORD' \
-H 'Content-Type: application/json' \
-d '{
        "source": "perplexity",
        "prompt": "best supplements for better sleep",
        "geo_location": "United States",
        "parse": true
    }'
```

{% endtab %}

{% tab title="Python" %}

```python
import requests
from pprint import pprint


# Structure payload.
payload = {
    'source': 'perplexity',
    'prompt': 'top 3 smartphones in 2025, compare pricing across US marketplaces',
    'geo_location': 'United States',
    'parse': True
}

# Get a response.
response = requests.post(
    'https://realtime.oxylabs.io/v1/queries',
    auth=('USERNAME', 'PASSWORD'),
    json=payload
)

# Print prettified response to stdout.
pprint(response.json())
```

{% endtab %}

{% tab title="Node.js" %}

```javascript
const https = require("https");

const username = "USERNAME";
const password = "PASSWORD";
const body = {
    source: "perplexity",
    prompt: "top 3 smartphones in 2025, compare pricing across US marketplaces",
    geo_location: "United States",
    parse: true
};

const options = {
    hostname: "realtime.oxylabs.io",
    path: "/v1/queries",
    method: "POST",
    headers: {
        "Content-Type": "application/json",
        Authorization:
            "Basic " + Buffer.from(`${username}:${password}`).toString("base64"),
    },
};

const request = https.request(options, (response) => {
    let data = "";

    response.on("data", (chunk) => {
        data += chunk;
    });

    response.on("end", () => {
        const responseData = JSON.parse(data);
        console.log(JSON.stringify(responseData, null, 2));
    });
});

request.on("error", (error) => {
    console.error("Error:", error);
});

request.write(JSON.stringify(body));
request.end();
```

{% endtab %}

{% tab title="HTTP" %}

```http
https://realtime.oxylabs.io/v1/queries?source=perplexity&prompt=top%203%20smartphones%20in%202025%2C%20compare%20pricing%20across%20US%20marketplaces&geo_location=United%20States&parse=true&access_token=12345abcde
```

{% endtab %}

{% tab title="PHP" %}

```php
<?php

$params = array(
    'source' => 'perplexity',
    'prompt' => 'top 3 smartphones in 2025, compare pricing across US marketplaces',
    'geo_location' => 'United States',
    'parse' => true
);

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, "https://realtime.oxylabs.io/v1/queries");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($params));
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_USERPWD, "USERNAME" . ":" . "PASSWORD");


$headers = array();
$headers[] = "Content-Type: application/json";
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

$result = curl_exec($ch);
echo $result;

if (curl_errno($ch)) {
    echo 'Error:' . curl_error($ch);
}
curl_close($ch);
```

{% endtab %}

{% tab title="Golang" %}

```go
package main

import (
	"bytes"
	"encoding/json"
	"fmt"
	"io"
	"net/http"
)

func main() {
	const Username = "USERNAME"
	const Password = "PASSWORD"

	payload := map[string]interface{}{
		"source":       "perplexity",
		"prompt":       "top 3 smartphones in 2025, compare pricing across US marketplaces",
		"geo_location": "United States",
		"parse":        true,
	}

	jsonValue, _ := json.Marshal(payload)

	client := &http.Client{}
	request, _ := http.NewRequest("POST",
		"https://realtime.oxylabs.io/v1/queries",
		bytes.NewBuffer(jsonValue),
	)

	request.SetBasicAuth(Username, Password)
	response, _ := client.Do(request)

	responseText, _ := io.ReadAll(response.Body)
	fmt.Println(string(responseText))
}

```

{% endtab %}

{% tab title="C#" %}

```csharp
using System;
using System.Collections.Generic;
using System.Net.Http;
using System.Net.Http.Json;
using System.Threading.Tasks;

namespace OxyApi
{
    class Program
    {
        static async Task Main()
        {
            const string Username = "USERNAME";
            const string Password = "PASSWORD";

            var parameters = new
            {
                source = "perplexity",
                prompt = "top 3 smartphones in 2025, compare pricing across US marketplaces",
                geo_location = "United States",
                parse = true
            };

            var client = new HttpClient();

            Uri baseUri = new Uri("https://realtime.oxylabs.io");
            client.BaseAddress = baseUri;

            var requestMessage = new HttpRequestMessage(HttpMethod.Post, "/v1/queries");
            requestMessage.Content = JsonContent.Create(parameters);

            var authenticationString = $"{Username}:{Password}";
            var base64EncodedAuthenticationString = Convert.ToBase64String(System.Text.ASCIIEncoding.UTF8.GetBytes(authenticationString));
            requestMessage.Headers.Add("Authorization", "Basic " + base64EncodedAuthenticationString);

            var response = await client.SendAsync(requestMessage);
            var contents = await response.Content.ReadAsStringAsync();

            Console.WriteLine(contents);
        }
    }
}
```

{% endtab %}

{% tab title="Java" %}

```java
package org.example;

import okhttp3.*;
import org.json.JSONArray;
import org.json.JSONObject;
import java.util.concurrent.TimeUnit;

public class Main implements Runnable {
    private static final String AUTHORIZATION_HEADER = "Authorization";
    public static final String USERNAME = "USERNAME";
    public static final String PASSWORD = "PASSWORD";

    public void run() {
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("source", "perplexity");
        jsonObject.put("prompt", "top 3 smartphones in 2025, compare pricing across US marketplaces");
        jsonObject.put("geo_location", "United States");
        jsonObject.put("parse", true);

        Authenticator authenticator = (route, response) -> {
            String credential = Credentials.basic(USERNAME, PASSWORD);
            return response
                    .request()
                    .newBuilder()
                    .header(AUTHORIZATION_HEADER, credential)
                    .build();
        };

        var client = new OkHttpClient.Builder()
                .authenticator(authenticator)
                .readTimeout(180, TimeUnit.SECONDS)
                .build();

        var mediaType = MediaType.parse("application/json; charset=utf-8");
        var body = RequestBody.create(jsonObject.toString(), mediaType);
        var request = new Request.Builder()
                .url("https://realtime.oxylabs.io/v1/queries")
                .post(body)
                .build();

        try (var response = client.newCall(request).execute()) {
            if (response.body() != null) {
                try (var responseBody = response.body()) {
                    System.out.println(responseBody.string());
                }
            }
        } catch (Exception exception) {
            System.out.println("Error: " + exception.getMessage());
        }

        System.exit(0);
    }

    public static void main(String[] args) {
        new Thread(new Main()).start();
    }
}
```

{% endtab %}

{% tab title="JSON" %}

```json
{
    "source": "perplexity",
    "prompt": "top 3 smartphones in 2025, compare pricing across US marketplaces",
    "geo_location": "United States",
    "parse": true
}
```

{% endtab %}
{% endtabs %}

{% hint style="info" %}
**Note:** JavaScript rendering is enabled by default for all LLM sources. You do not need to include rendering parameters in your request payload.
{% endhint %}

We use synchronous [**Realtime**](/products/web-scraper-api/integration-methods/realtime.md) integration method in our examples. If you would like to use [**Proxy Endpoint**](/products/web-scraper-api/integration-methods/proxy-endpoint.md) or asynchronous [**Push-Pull**](/products/web-scraper-api/integration-methods/push-pull.md) integration, refer to the [**integration methods**](/products/web-scraper-api/integration-methods.md) section.

{% hint style="warning" %}
B**atch requests** are currently **not supported** for the `perplexity` source.&#x20;
{% endhint %}

### Request parameters

Basic setup and configuration parameters for scraping Perplexity responses.

<table><thead><tr><th width="222">Parameter</th><th width="350.3333333333333">Description</th><th>Default Value</th></tr></thead><tbody><tr><td><mark style="background-color:green;"><strong><code>source</code></strong></mark></td><td>Sets the scraper target. Use <code>perplexity</code>.</td><td>–</td></tr><tr><td><mark style="background-color:green;"><strong><code>prompt</code></strong></mark></td><td>The prompt or question to submit to Perplexity. Must be under 8000 characters.</td><td>–</td></tr><tr><td><code>parse</code></td><td>Set to <code>true</code> for structured JSON data.</td><td><code>false</code></td></tr><tr><td><code>geo_location</code></td><td>Specify a country to route the request from. <a href="/spaces/BQ7Zf9paoN3FTeGcyfY1/pages/0I4VTnd54ZqcMpbB6L0s"><strong>More info</strong></a>.</td><td>–</td></tr><tr><td><code>callback_url</code></td><td>URL to your callback endpoint. <a href="https://developers.oxylabs.io/products/web-scraper-api/integration-methods/push-pull"><strong>More info</strong></a></td><td>–</td></tr></tbody></table>

&#x20;    \- mandatory parameter

## Structured data

Web Scraper API returns either an HTML document or a JSON object of Perplexity's output, which contains structured data from the results page.

<details>

<summary><code>perplexity</code> structured output</summary>

```json
{
  "results": [
    {
      "job_id": "7470032181138587649",
      "status_code": 200,
      "url": "https://www.perplexity.ai/search/915bee3e-2d59-48ba-8b19-701f527c9b60",
      "content": {
        "prompt_query": "best supplements for better sleep",
        "model": "turbo",
        "answer_results": [
          "Here are the most evidence-supported supplements people typically try for better sleep—plus who they're best for and key safety notes.",
          "Best-supported options (start here)",
          ...
        ],
        "answer_results_md": "\nHere are the most evidence-supported supplements people typically try for better sleep—plus who they're best for and key safety notes.\n\nBest-supported options (start here)\n-----------------------------------\n\n...",
        "additional_results": {
          "sources_results": [
            {
              "title": "Best Supplements and Habits for Better Sleep (20 min.)",
              "url": "https://coopercomplete.com/blog/best-supplements-for-better-sleep/"
            },
            {
              "title": "Sleep Better With These 9 Sleep Supplements",
              "url": "https://drruscio.com/sleep-supplements/"
            },
            {
              "title": "10 Best Supplements for Sleep Support: A Dietitian's Picks",
              "url": "https://letsliveitup.com/blogs/supergreens/best-sleep-supplements"
            },
            ...
          ]
        },
        "related_queries": [
          "Which sleep aids have the strongest evidence in adults",
          "How to cycle supplements for sleep without tolerance",
          "What are safest melatonin dosing guidelines for adults",
          "Lifestyle tweaks to maximize sleep while using supplements"
        ],
        "displayed_tabs": [
          "Answer",
          "Links",
          "Images"
        ],
        "url": "https://www.perplexity.ai/search/915bee3e-2d59-48ba-8b19-701f527c9b60",
        "parse_status_code": 12000
      }
    }
  ]
}
```

</details>

### Output data dictionary

#### **HTML example**

<div data-full-width="false"><figure><img src="/files/mz9LqDTSlc24eUxIOqOv" alt=""><figcaption></figcaption></figure></div>

#### **JSON structure**

All LLM targets return the same top-level `job` and `results[]` envelope. See [LLMs and AI](/api-targets/llms-and-ai.md) for the full metadata reference.

The following table shows Perplexity-specific `results[].content` fields:

{% hint style="info" %}
The number of items and fields for a specific result type may vary depending on the submitted prompt.
{% endhint %}

<table><thead><tr><th width="171">Field</th><th width="408">Description</th><th>Type</th></tr></thead><tbody><tr><td><code>prompt_query</code></td><td>Submitted prompt or search query.</td><td>string</td></tr><tr><td><code>model</code></td><td>Perplexity model used for the response (e.g., <code>turbo</code>).</td><td>string</td></tr><tr><td><code>answer_results</code></td><td>Generated answer as Markdown JSON tree.</td><td>array</td></tr><tr><td><code>answer_results_md</code></td><td>Generated answer in Markdown</td><td>string</td></tr><tr><td><mark style="background-color:yellow;"><code>additional_results</code></mark></td><td>Grouped UI elements. <code>sources_results</code> – list of web sources Perplexity used (<code>title</code> and <code>url</code>). Can include <code>images_results</code>, <code>hotels_results</code>, <code>places_results</code>, <code>videos_results</code>, and <code>shopping_results</code>.</td><td>object</td></tr><tr><td><mark style="background-color:yellow;"><code>top_images</code></mark></td><td>Perplexity image results on the "Images" tab. Objects include <code>url</code> and <code>title</code>.</td><td>array</td></tr><tr><td><mark style="background-color:yellow;"><code>top_sources</code></mark></td><td>Perplexity top-ranked source results. Objects include <code>url</code>, <code>title</code>, and <code>source</code>.</td><td>array</td></tr><tr><td><mark style="background-color:yellow;"><code>inline_products</code></mark></td><td>Shopping results triggered by product-related queries.</td><td>array</td></tr><tr><td><mark style="background-color:yellow;"><code>related_queries</code></mark></td><td>Suggested follow-up questions by Perplexity.</td><td>array of strings</td></tr><tr><td><code>displayed_tabs</code></td><td>UI tabs visible on the parsed page (e.g., Answer, Links, Images).</td><td>array of strings</td></tr><tr><td><code>url</code></td><td>The URL of the Perplexity search page for this query.</td><td>string</td></tr><tr><td><code>parse_status_code</code></td><td><code>12000</code> – successful. Otherwise, parser failed to extract some or all structured fields.</td><td>integer</td></tr></tbody></table>

&#x20;    – conditional, returned only when content is in the LLM's response.

#### Additional results and inline products

Along with the main AI response, we return extra data under `additional_results`, such as

* `sources_results`
* `images_results`
* `shopping_results`
* `videos_results`
* `places_results`
* `hotels_results`

These arrays are extracted from the tabs on the original results page and are included only if relevant content is available:

<figure><img src="/files/8Saib7A5elgAiKmla2o2" alt=""><figcaption></figcaption></figure>

The `inline_products` array also contains products that are directly embedded in the response:

<figure><img src="/files/eiavBG5QQkDGvFHrGYSk" alt=""><figcaption></figcaption></figure>


---

# 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:

```
GET https://developers.oxylabs.io/api-targets/llms-and-ai/perplexity.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
