> 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/llm-he-ai/chatgpt.md).

# ChatGPT

该 `chatgpt` 该源允许你向 ChatGPT 提交提示，并接收完全解析、结构化的响应，包括纯文本和 Markdown 答案、来源引用、模型使用的搜索查询，以及购物产品和广告。

## 请求示例

以下代码示例演示如何提交提示并获取带解析结果的 ChatGPT 响应。

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

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

{% endtab %}

{% tab title="Python" %}

```python
import requests
from pprint import pprint

# Structure payload.
payload = {
    'source': 'chatgpt',
    'prompt': 'best supplements for better sleep',
    'parse': True,
    'geo_location': "United States"
}

# Get response.
response = requests.request(
    '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: "chatgpt",
    prompt: "best supplements for better sleep",
    parse: true,
    geo_location: "United States"
};

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=chatgpt&prompt=best%20supplements%20for%20better%20sleep&parse=true&geo_location=United%20States&access_token=12345abcde
```

{% endtab %}

{% tab title="PHP" %}

```php
<?php

$params = array(
    'source' => 'chatgpt',
    'prompt' => 'best supplements for better sleep',
    'parse' => true,
    'geo_location' => "United States"
);

$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="Go语言" %}

```go
package main

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

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

  	payload := map[string]interface{}{
        	"source": "chatgpt",
        	"prompt": "best supplements for better sleep",
        	"parse":  true,
        	"geo_location": "United States"
    	}

	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, _ := ioutil.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 = "chatgpt",
                prompt = "best supplements for better sleep",
                parse = true,
                geo_location = "United States"
            };

            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", "chatgpt");
        jsonObject.put("prompt", "best supplements for better sleep");
        jsonObject.put("parse", true);
        jsonObject.put("geo_location", "United States");

        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": "chatgpt",
        "prompt": "best supplements for better sleep",
        "parse": true,
        "geo_location": "United States"
}
```

{% endtab %}
{% endtabs %}

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

我们在示例中使用同步 [**Realtime**](/products/cn/web-scraper-api/integration-methods/realtime.md) 集成方式。如果你想使用 [**Proxy Endpoint**](/products/cn/web-scraper-api/integration-methods/proxy-endpoint.md) 或异步 [**Push-Pull**](/products/cn/web-scraper-api/integration-methods/push-pull.md) 集成（包括 [批量查询](/products/cn/web-scraper-api/integration-methods/push-pull.md#batch-query)），请参阅 [**集成方式**](/products/cn/web-scraper-api/integration-methods.md) 部分。

### 请求参数

抓取 ChatGPT 的基本设置和自定义选项。

<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>chatgpt</code>.</td><td>–</td></tr><tr><td><mark style="background-color:green;"><strong><code>prompt</code></strong></mark></td><td>要提交给 ChatGPT 的提示或问题。必须少于 4000 个字符。</td><td>–</td></tr><tr><td><code>search</code></td><td>设置为 <code>true</code> 用于网页搜索。</td><td><code>false</code></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="/spaces/ZwEHB9k4MH4pDy80n9mF/pages/eb847b3738ee0ad9f321c5de8b8291a0dd7ff7af"><strong>更多信息</strong></a>.</td><td>–</td></tr><tr><td><code>browser_instructions</code></td><td>在渲染 JavaScript 时可选的自定义浏览器指令。 <a href="/spaces/ZwEHB9k4MH4pDy80n9mF/pages/9d7133837001de31de5dfd0796cfbc6fdd7c78c8#browser-instructions"><strong>更多信息</strong></a>.</td><td>–</td></tr><tr><td><code>callback_url</code></td><td>你的回调端点 URL。 <a href="https://developers.oxylabs.io/products/web-scraper-api/integration-methods/push-pull"><strong>更多信息</strong></a></td><td>–</td></tr></tbody></table>

&#x20;    \- 必填参数

## 结构化数据

网页爬虫API 可以返回包含 ChatGPT 输出的 HTML 或 JSON 对象，其中含有结果页面各元素的结构化数据。

<details>

<summary><code>chatgpt</code> 结构化输出</summary>

```json
{
  "results": [
    {
      "job_id": "7470033199733683201",
      "status_code": 200,
      "url": "https://chatgpt.com/?model=auto",
      "content": {
        "prompt": "best supplements for better sleep",
        "llm_model": "gpt-5-5",
        "response_text": "If you're looking for supplements with the best evidence for improving sleep, I'd rank them roughly like this: 1. Magnesium glycinate Best all-around starting point for many people ...",
        "markdown_text": "If you're looking for supplements with the best evidence for improving sleep, I'd rank them roughly like this:\n\n### 1. Magnesium glycinate\n\n**Best all-around starting point for many people**\n\n* ...",
        "markdown_json": [
          {
            "type": "paragraph",
            "children": [
              {
                "type": "text",
                "raw": "If you're looking for supplements with the best evidence for improving sleep, I'd rank them roughly like this:"
              }
            ]
          },
          {
            "type": "blank_line"
          },
          ...
        ],
        "citations": [
          {
            "title": "Best Sleep Supplements: Evidence-Based Gui | Holistic Health",
            "url": "https://holistic.health/journal/best-sleep-supplements-beyond-melatonin?utm_source=chatgpt.com",
            "text": "Holistic Health",
            "description": "May 26, 2026"
          },
          {
            "title": "Natural Sleep Aids: Which Are the Most Effective?",
            "url": "https://www.sleepfoundation.org/sleep-aids/natural-sleep-aids?utm_source=chatgpt.com",
            "text": "sleepfoundation.org",
            "description": "July 14, 2025 — NATURAL SLEEP AIDS: WHICH ARE THE MOST EFFECTIVE?  Updated July 15, 2025  Written by Lucy Bryan ...",
            "section": "more"
          },
          {
            "title": "Do Magnesium Sleep Drinks Really Work? What the Science Says",
            "url": "https://www.health.com/magnesium-drink-before-bed-11920427?utm_source=chatgpt.com",
            "text": "Health",
            "description": "Magnesium sleep drinks are beverages containing powdered magnesium and often calming ingredients like herbs or amino acids..."
          },
          ...
        ],
        "search_queries": [
          "best supplements for sleep evidence melatonin magnesium valerian 2025"
        ],
        "parse_status_code": 12000
      }
    }
  ]
}
```

</details>

{% hint style="warning" %}
响应的组成可能会因查询是否来自 **桌面** 或 **移动端** 设备。
{% endhint %}

### 输出数据字典

#### HTML 示例

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

#### JSON 结构

所有 LLM 目标都返回相同的顶级 `任务` 和 `results[]` 封装。参见 [LLMs 和 AI](/api-targets/cn/llm-he-ai.md) 以查看完整的元数据参考。

下表显示 ChatGPT 特定的 `results[].content` 字段：

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

<table><thead><tr><th width="173">字段</th><th width="476">描述</th><th width="90">类型</th></tr></thead><tbody><tr><td><code>prompt</code></td><td>用于生成结果的提交提示。</td><td>字符串</td></tr><tr><td><code>llm_model</code></td><td>用于响应的具体 ChatGPT 模型（例如， <code>gpt-4o</code>).</td><td>字符串</td></tr><tr><td><code>response_text</code></td><td>来自 ChatGPT 的纯文本响应。</td><td>字符串</td></tr><tr><td><code>markdown_text</code></td><td>以 Markdown 形式返回的 ChatGPT 响应。</td><td>字符串</td></tr><tr><td><code>markdown_json</code></td><td>Markdown 响应的结构化 JSON 表示。每一项都包含 <code>type</code> 和 <code>children</code>.</td><td>数组</td></tr><tr><td><mark style="background-color:yellow;"><code>citations</code></mark></td><td>响应来源引用列表。对象包含 <code>title</code>, <code>url</code>, <code>text</code>, <code>description</code>，以及 <code>section</code>.</td><td>数组</td></tr><tr><td><mark style="background-color:yellow;"><code>search_queries</code></mark></td><td>模型用于收集信息的搜索查询。</td><td>字符串数组</td></tr><tr><td><mark style="background-color:yellow;"><code>链接</code></mark></td><td>用于内联源链接详情的对象列表： <code>url</code> 和 <code>text</code>.</td><td>数组</td></tr><tr><td><mark style="background-color:yellow;"><code>shopping_products</code></mark></td><td>包含产品详情的对象列表： <code>price</code>, <code>title</code>, <code>rating</code>, <code>currency</code>, <code>price_str</code>，以及 <code>thumbnail</code>.</td><td>数组</td></tr><tr><td><mark style="background-color:yellow;"><code>ads</code></mark></td><td>包含广告详情的 <code>url</code>, <code>title</code>, <code>image_url</code>, <code>description</code>，以及一个 <code>advertiser_info</code> 对象。</td><td>数组</td></tr><tr><td><mark style="background-color:yellow;"><code>ads.advertiser_info</code></mark></td><td>包含广告主 <code>url</code>, <code>名称</code>，以及 <code>image_url</code></td><td>对象</td></tr><tr><td><code>parse_status_code</code></td><td><code>12000</code> – 成功。否则，解析器未能提取部分或全部结构化字段。</td><td>整数</td></tr></tbody></table>

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


---

# 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/llm-he-ai/chatgpt.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.
