注册

web搜索

Web Search

POST https://api.quickrouter.ai/v1/chat/completions 在线调试 →
Authorization

在 Header 添加参数 Authorization,其值为 Bearer 之后拼接 Token

示例: Authorization: Bearer ********************

请求参数

Header 参数
Content-Type string
必需
示例: application/json
Authorization string
必需
示例: Bearer $OPENAI_API_KEY
Body 参数 application/json
model string
必需
要使用的模型的 ID,如 gpt-4o-search-preview。
web_search_options object
必需
网页搜索选项,传入空对象 {} 即可启用搜索功能。
messages array [object]
必需
至今为止对话所包含的消息列表。
示例
{
    "model": "gpt-4o-search-preview",
    "web_search_options": {},
    "messages": [
        {
            "role": "user",
            "content": "What was a positive news story from today?"
        }
    ]
}

请求示例代码

curl --location --request POST 'https://api.quickrouter.ai/v1/chat/completions' \
--header 'Authorization: Bearer <token>' \
--header 'Content-type: application/json' \
--data-raw '{
    "model": "gpt-4o-search-preview",
    "web_search_options": {},
    "messages": [
        {
            "role": "user",
            "content": "What was a positive news story from today?"
        }
    ]
}'
var myHeaders = new Headers();
myHeaders.append("Authorization", "Bearer <token>");
myHeaders.append("Content-type", "application/json");

var raw = JSON.stringify({
   "model": "gpt-4o-search-preview",
   "web_search_options": {},
   "messages": [
      {
         "role": "user",
         "content": "What was a positive news story from today?"
      }
   ]
});

var requestOptions = {
   method: 'POST',
   headers: myHeaders,
   body: raw,
   redirect: 'follow'
};

fetch("https://api.quickrouter.ai/v1/chat/completions", requestOptions)
   .then(response => response.text())
   .then(result => console.log(result))
   .catch(error => console.log('error', error));
import http.client
import json

conn = http.client.HTTPSConnection("api.quickrouter.ai")
payload = json.dumps({
   "model": "gpt-4o-search-preview",
   "web_search_options": {},
   "messages": [
      {
         "role": "user",
         "content": "What was a positive news story from today?"
      }
   ]
})
headers = {
   'Authorization': 'Bearer <token>',
   'Content-type': 'application/json'
}
conn.request("POST", "/v1/chat/completions", payload, headers)
res = conn.getresponse()
data = res.read()
print(data.decode("utf-8"))

返回响应

响应参数 🟢 200 OK · application/json
object string
必需
choices array [object]
必需
usage object
必需
示例
{
    "id": "chatcmpl-123",
    "object": "chat.completion",
    "created": 1677652288,
    "choices": [
        {
            "index": 0,
            "message": {
                "role": "assistant",
                "content": "Here is a positive news story from today..."
            },
            "finish_reason": "stop"
        }
    ],
    "usage": {
        "prompt_tokens": 20,
        "completion_tokens": 50,
        "total_tokens": 70
    }
}