Workbench 开发者文档English

Serper

基础 URL

https://desktop-api.wbench.io/v1/proxy/serper/

Serper 文档中使用 https://google.serper.dev/ 的地方,请改用 https://desktop-api.wbench.io/v1/proxy/serper/。

这就是 Serper 自己的 API

基础 URL 之后的部分就是 Serper 的 API ,与 Serper 的文档完全一致:相同的路径、方法、查询参数和 JSON 正文。唯一的区别是地址和凭据:您发送自己的 Workbench 令牌,Workbench 在服务器上加上贵公司的 Serper 密钥。您永远看不到这个密钥。

说明

示例

先设置 WB_TOKEN:export WB_TOKEN=$(wb token)。

wb

wb call serper search --data '{"q": "MMBT3904 datasheet"}'

curl

curl "https://desktop-api.wbench.io/v1/proxy/serper/search" \
  -H "Authorization: Bearer $(wb token)" \
  -H "Content-Type: application/json" \
  -d '{"q": "MMBT3904 datasheet"}'

Python

Serper 没有官方的 Python 或 TypeScript SDK,因此这些示例直接使用 HTTP。

import os
import requests

headers = {"Authorization": f"Bearer {os.environ['WB_TOKEN']}"}
r = requests.post(
    "https://desktop-api.wbench.io/v1/proxy/serper/search",
    headers=headers,
    json={"q": "MMBT3904 datasheet"},
    timeout=60,
)
r.raise_for_status()
print(r.json())

TypeScript

const r = await fetch("https://desktop-api.wbench.io/v1/proxy/serper/search", {
  method: "POST",
  headers: { Authorization: `Bearer ${process.env.WB_TOKEN}`, "Content-Type": "application/json" },
  body: JSON.stringify({"q": "MMBT3904 datasheet"}),
});
if (!r.ok) throw new Error(`${r.status}: ${(await r.json()).message}`);
console.log(await r.json());

请求被拒绝时的响应格式见限制与错误。