跳转到主要内容
Endpoint: GET /customsearch/v1 使用你提供的 cx 调用 Google Custom Search。如果省略 cx,则使用 YouRouter 的默认搜索引擎。 这个接口适合获取新鲜网页结果、文档检索,或者为你自己的站点接入 Programmable Search Engine。
搜索请求也适用 零完成保险。失败或空搜索结果不会按成功 completion 计费。
import requests
import json

response = requests.get(
    "https://api.yourouter.ai/customsearch/v1",
    headers={"Authorization": "Bearer YOUR_API_KEY"},
    params={
        "q": "how to set up billing",
        "cx": "YOUR_CUSTOM_SEARCH_ENGINE_ID",
        "num": 3
    }
)
print(json.dumps(response.json(), indent=2))

参数

参数类型说明必填
qstring搜索关键词。
cxstringCustom Search Engine ID。省略时使用 YouRouter 默认搜索引擎。
numinteger返回结果数量,范围 1 到 10。
startinteger返回结果的起始索引。
siteSearchstring限定在特定站点内搜索。

响应格式

成功响应中会包含一个 items 数组,数组中的每个元素都是一条搜索结果对象。
{
  "kind": "customsearch#search",
  "items": [
    {
      "kind": "customsearch#result",
      "title": "Billing Information - Example Docs",
      "link": "https://docs.example-app.ai/billing"
    }
  ]
}

典型使用场景

你可以为自己的文档域名配置一个 Google Programmable Search Engine,然后先把搜索结果取回来,再交给模型生成更具时效性的产品问答结果。
先用搜索结果获取最新文章、网页或公告,再让模型做摘要、比较或推理。