> 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/cn/llms-and-ai/perplexity.md).

# Perplexity

通过提交提示词提取 Perplexity 响应，并获取包含答案文本、Markdown 输出、相关查询、引用来源、图片、内嵌产品等的解析后数据。

该 `perplexity` source 允许您提交提示并接收完全解析、结构化的响应，包括格式化答案、使用的网页来源、相关查询和显示的 UI 标签页。与产品相关的提示可返回购物结果和内联产品列表。

## 请求示例

下面的代码示例演示如何使用 Perplexity 发送提示 [**Push-Pull**](/products/cn/web-scraper-api/integration-methods/push-pull.md).

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

```bash
curl 'https://data.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,
        "callback_url": "https://your-server.com/oxylabs-callback"
    }'
```

{% endtab %}

{% tab title="Python" %}

```python
import requests
from pprint import pprint


# 结构化载荷。
payload = {
    'source': 'perplexity',
    'prompt': 'top 3 smartphones in 2025, compare pricing across US marketplaces',
    'geo_location': 'United States',
    'parse': True,
    'callback_url': 'https://your-server.com/oxylabs-callback'
}

# Get a response.
response = requests.post(
    'https://data.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",
    解析：true,
    callback_url: "https://your-server.com/oxylabs-callback"
};

const options = {
    hostname: "data.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="PHP" %}

```php
<?php

$params = array(
    'source' => 'perplexity',
    'prompt' => 'top 3 smartphones in 2025, compare pricing across US marketplaces',
    'geo_location' => 'United States',
    'parse' => true,
    'callback_url' => 'https://your-server.com/oxylabs-callback'
);

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, "https://data.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,
		"callback_url": "https://your-server.com/oxylabs-callback",
	}

	jsonValue, _ := json.Marshal(payload)

	client := &http.Client{}
	request, _ := http.NewRequest("POST",
		"https://data.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,
                callback_url = "https://your-server.com/oxylabs-callback"
            };

            var client = new HttpClient();

            Uri baseUri = new Uri("https://data.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;

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);
        jsonObject.put("callback_url", "https://your-server.com/oxylabs-callback");

        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)
                .build();

        var mediaType = MediaType.parse("application/json; charset=utf-8");
        var body = RequestBody.create(jsonObject.toString(), mediaType);
        var request = new Request.Builder()
                .url("https://data.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,
    "callback_url": "https://your-server.com/oxylabs-callback"
}
```

{% endtab %}
{% endtabs %}

{% hint style="info" %}
**注意：** 所有 LLM 来源默认启用 JavaScript 渲染。您无需在请求负载中包含渲染参数。
{% endhint %}

使用以下方式提交作业 [**Push-Pull**](/products/cn/web-scraper-api/integration-methods/push-pull.md) 集成（包括 [批量查询](/products/cn/web-scraper-api/integration-methods/push-pull.md#batch-query)) 方法会立即返回作业 ID，而不是结果。一旦作业状态为 `done`，即可获取解析后的响应。参见 [**集成方式**](/api-targets/cn/llms-and-ai.md#integration-method) LLMs 和 AI 页面上的完整提交与检索流程。

### 请求参数

用于抓取 Perplexity 响应的基本设置和配置参数。

<table><thead><tr><th width="222">参数</th><th width="350.3333333333333">描述</th><th>默认值</th></tr></thead><tbody><tr><td><mark style="background-color:green;"><strong><code>source</code></strong></mark></td><td>设置爬虫目标。使用 <code>perplexity</code>.</td><td>–</td></tr><tr><td><mark style="background-color:green;"><strong><code>prompt</code></strong></mark></td><td>提交给 Perplexity 的提示或问题。必须少于 8000 个字符。</td><td>–</td></tr><tr><td><code>callback_url</code></td><td><strong>推荐。</strong> 作业完成后我们发送通知的 URL。 <a href="https://developers.oxylabs.io/products/web-scraper-api/integration-methods/push-pull"><strong>更多信息</strong></a><strong>.</strong></td><td>–</td></tr><tr><td><code>解析</code></td><td>设置为 <code>true</code> 用于结构化 JSON 数据。</td><td><code>false</code></td></tr><tr><td><code>geo_location</code></td><td>指定请求路由所在的国家/地区。 <a href="/products/cn/web-scraper-api/features/localization.md"><strong>更多信息</strong></a>.</td><td>–</td></tr><tr><td><code>browser_instructions</code></td><td>渲染 JavaScript 时的可选自定义浏览器指令。 <a href="/products/cn/web-scraper-api/features/js-rendering-and-browser-control.md#browser-instructions"><strong>更多信息</strong></a>.</td><td>–</td></tr></tbody></table>

\- 必填参数

## 结构化数据

一旦通过 Push-Pull 结果端点检索到任务，网页爬虫API 将返回 HTML 文档或 Perplexity 输出的 JSON 对象，其中包含结果页中的结构化数据。

<details>

<summary><code>perplexity</code> 结构化输出</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>

### 输出数据字典

#### **HTML 示例**

<div data-full-width="false"><figure><img src="https://1830353461-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FBaJCXoqO1zdFnaMnCKrg%2Fuploads%2Fgit-blob-ef207530518e24ade4809399d1578709157cceb2%2Fhtml_sample.png?alt=media" alt=""><figcaption></figcaption></figure></div>

#### **JSON 结构**

所有 LLM 目标返回相同的顶层 `作业` 和 `results[]` 封装。参见 [LLMs 和 AI](/api-targets/cn/llms-and-ai.md) 以查看完整的元数据参考。

下表显示 Perplexity 特有的 `results[].content` 字段：

{% hint style="info" %}
特定结果类型的项数和字段数可能因提交的提示而异。
{% endhint %}

<table><thead><tr><th width="171">字段</th><th width="408">描述</th><th>类型</th></tr></thead><tbody><tr><td><code>prompt_query</code></td><td>提交的提示或搜索查询。</td><td>字符串</td></tr><tr><td><code>model</code></td><td>响应所使用的 Perplexity 模型（例如， <code>turbo</code>).</td><td>字符串</td></tr><tr><td><code>answer_results</code></td><td>以 Markdown JSON 树形式生成的答案。</td><td>数组</td></tr><tr><td><code>answer_results_md</code></td><td>以 Markdown 形式生成的答案</td><td>字符串</td></tr><tr><td><mark style="background-color:yellow;"><code>additional_results</code></mark></td><td>分组的 UI 元素。 <code>sources_results</code> – Perplexity 使用的网页来源列表（<code>title</code> 和 <code>url</code>）。可包括 <code>images_results</code>, <code>hotels_results</code>, <code>places_results</code>, <code>videos_results</code>，以及 <code>shopping_results</code>.</td><td>对象</td></tr><tr><td><mark style="background-color:yellow;"><code>top_images</code></mark></td><td>Perplexity 在“Images”标签页上的图片结果。对象包括 <code>url</code> 和 <code>title</code>.</td><td>数组</td></tr><tr><td><mark style="background-color:yellow;"><code>top_sources</code></mark></td><td>Perplexity 排名靠前的来源结果。对象包括 <code>url</code>, <code>title</code>，以及 <code>source</code>.</td><td>数组</td></tr><tr><td><mark style="background-color:yellow;"><code>inline_products</code></mark></td><td>由与产品相关的查询触发的购物结果。</td><td>数组</td></tr><tr><td><mark style="background-color:yellow;"><code>related_queries</code></mark></td><td>Perplexity 建议的后续问题。</td><td>字符串数组</td></tr><tr><td><code>displayed_tabs</code></td><td>解析后页面上可见的 UI 标签页（例如 Answer、Links、Images）。</td><td>字符串数组</td></tr><tr><td><code>url</code></td><td>此查询对应的 Perplexity 搜索页面 URL。</td><td>字符串</td></tr><tr><td><code>parse_status_code</code></td><td><code>12000</code> – 成功。否则，解析器未能提取部分或全部结构化字段。</td><td>整数</td></tr></tbody></table>

– 条件返回，仅在内容出现在 LLM 响应中时返回。

#### 额外结果和内联产品

除了主要的 AI 响应外，我们还会在 `additional_results`下返回额外数据，例如

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

这些数组从原始结果页的标签页中提取，仅在存在相关内容时包含：

<figure><img src="https://1830353461-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FBaJCXoqO1zdFnaMnCKrg%2Fuploads%2Fgit-blob-0512e02c47dc4da02926f522d1642c7efd4aea6f%2Fadditiona_results.png?alt=media" alt=""><figcaption></figcaption></figure>

该 `inline_products` 数组还包含直接嵌入响应中的产品：

<figure><img src="https://1830353461-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FBaJCXoqO1zdFnaMnCKrg%2Fuploads%2Fgit-blob-91078cb5f89e081f44d7fbc678f449050435aebf%2Finline.png?alt=media" 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, and the optional `goal` query parameter:

```
GET https://developers.oxylabs.io/api-targets/cn/llms-and-ai/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.
