> 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/products/cn/web-scraper-api/mu-biao/llms-he-ai/perplexity.md). Agents can also search and read this documentation through its [MCP server](https://developers.oxylabs.io/~gitbook/mcp).

# Perplexity

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

该 `perplexity` source 字段允许您提交提示，并接收完全解析、结构化的响应，包括格式化答案、使用的网页来源、相关查询以及显示的 UI 选项卡。

## 请求示例

下面的代码示例说明如何使用以下方式向 Perplexity 发送提示 [**Push-Pull**](https://developers.oxylabs.io/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": "2026 年排名前三的智能手机，比较美国各市场的价格",
        "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


# Structure payload.
payload = {
    'source': 'perplexity',
    'prompt': '2026 年排名前三的智能手机，比较美国各市场的价格',
    'geo_location': 'United States',
    'parse': True,
    'callback_url': 'https://your-server.com/oxylabs-callback'
}

# 获取响应。
response = requests.post(
    'https://data.oxylabs.io/v1/queries',
    auth=('USERNAME', 'PASSWORD'),
    json=payload
)

# 将格式化后的响应打印到标准输出。
pprint(response.json())
```

{% endtab %}

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

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

const username = "USERNAME";
const password = "PASSWORD";
const body = {
    source: "perplexity",
    prompt: "2026 年排名前三的智能手机，比较美国各市场的价格",
    geo_location: "United States",
    parse: 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' => '2026 年排名前三的智能手机，比较美国各市场的价格',
    '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":       "2026 年排名前三的智能手机，比较美国各市场的价格",
		"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 = "2026 年排名前三的智能手机，比较美国各市场的价格",
                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", "2026 年排名前三的智能手机，比较美国各市场的价格");
        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": "2026 年排名前三的智能手机，比较美国各市场的价格",
    "geo_location": "United States",
    "parse": true,
    "callback_url": "https://your-server.com/oxylabs-callback"
}
```

{% endtab %}
{% endtabs %}

使用以下方式提交任务 [**Push-Pull**](https://developers.oxylabs.io/products/cn/web-scraper-api/integration-methods/push-pull.md) 集成方法（包括 [批量查询](https://developers.oxylabs.io/products/cn/web-scraper-api/integration-methods/push-pull.md#batch-query)) 方法会立即返回 job ID，而不是结果。待任务状态为 `完成`时，获取解析后的响应。参见 [**集成方法**](https://developers.oxylabs.io/products/cn/web-scraper-api/integration-methods.md) 在 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 的提示或问题。最多 8,000 个字符。</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>parse</code></td><td>设为 <code>true</code> 用于结构化 JSON 数据。</td><td><code>false</code></td></tr><tr><td><code>geo_location</code></td><td>指定请求路由来源国家。 <a href="https://developers.oxylabs.io/products/cn/web-scraper-api/features/localization.md"><strong>更多信息</strong></a>.</td><td>–</td></tr></tbody></table>

&#x20;   \- 必填参数

## 结构化数据

一旦通过 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": "\n这里列出了人们通常会尝试、且证据支持度最高的助眠补充剂——以及它们最适合的人群和关键安全提示。\n\n最佳支持的选项（从这里开始）\n-----------------------------------\n\n...",
        "additional_results": {
          "sources_results": [
            {
              "title": "最佳补充剂与助眠习惯（20 分钟）",
              "url": "https://coopercomplete.com/blog/best-supplements-for-better-sleep/"
            },
            {
              "title": "通过这 9 种助眠补充剂睡得更好",
              "url": "https://drruscio.com/sleep-supplements/"
            },
            {
              "title": "睡眠支持的 10 种最佳补充剂：营养师推荐",
              "url": "https://letsliveitup.com/blogs/supergreens/best-sleep-supplements"
            },
            ...
          ]
        },
        "related_queries": [
          "成年人中哪些助眠产品有最强证据支持",
          "如何轮换使用助眠补充剂而不产生耐受",
          "成人最安全的褪黑素剂量指南是什么",
          "在使用补充剂时最大化睡眠的生活方式调整"
        ],
        "displayed_tabs": [
          "答案",
          "链接",
          "图片"
        ],
        "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://3714446197-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FBQ7Zf9paoN3FTeGcyfY1%2Fuploads%2Fgit-blob-ef207530518e24ade4809399d1578709157cceb2%2Fhtml_sample.png?alt=media" alt=""><figcaption></figcaption></figure></div>

#### **JSON 结构**

所有 LLM 目标都会返回相同的顶级 `job` 和 `results[]` 封装。参见 [LLMs 和 AI](https://developers.oxylabs.io/api-reference/cn/zhuan-yong-zhua-qu-qi/llm-yu-ai-zhua-qu-qi.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>.</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>raw_response</code></td><td>来自 Perplexity 的原始流式响应，每项一行。</td><td>字符串数组</td></tr><tr><td><code>parse_status_code</code></td><td><code>12000</code> – 成功。否则，解析器未能提取部分或全部结构化字段。</td><td>整数</td></tr></tbody></table>

&#x20;    － 条件性返回，仅当内容出现在 LLM 的响应中。

#### 附加结果和内嵌产品

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

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

这些数组是从原始结果页的选项卡中提取的，仅在存在相关内容时才包含：

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

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

<figure><img src="https://3714446197-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FBQ7Zf9paoN3FTeGcyfY1%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 by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://developers.oxylabs.io/products/cn/web-scraper-api/mu-biao/llms-he-ai/perplexity.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
