SDKs
Node.js / TypeScript
Thunderbit Open API 的 Node.js 地道寫法
Thunderbit API 用 Node 18+ 內建的 fetch 就能跑 —— 不需要 SDK。要 HTTP/2 與連線池來扛量,可以換 undici 或 axios。
設定
const API = "https://openapi.thunderbit.com/openapi/v1";
const H = {
"Authorization": `Bearer ${process.env.THUNDERBIT_API_KEY}`,
"Content-Type": "application/json",
};Distill 一個頁面
const r = await fetch(`${API}/distill`, {
method: "POST",
headers: H,
body: JSON.stringify({ url: "https://thunderbit.com/playground" }),
});
const { data } = await r.json();
console.log(data.markdown);Extract 結構化資料
type Product = { name: string; price: number; currency?: string };
const r = await fetch(`${API}/extract`, {
method: "POST",
headers: H,
body: JSON.stringify({
url: "https://example.com/product/iphone-15-pro",
schema: {
type: "object",
properties: {
name: { type: "string" },
price: { type: "number" },
},
required: ["name", "price"],
},
}),
});
const { data } = await r.json() as { data: Product };Batch + Webhook(TypeScript)
const job = await fetch(`${API}/batch/distill`, {
method: "POST",
headers: H,
body: JSON.stringify({
urls: ["https://example.com/page1", "https://example.com/page2"],
webhook: {
url: "https://your-server.com/webhook",
secret: process.env.WEBHOOK_SECRET,
},
}),
}).then(r => r.json());在你的 handler 裡驗證 Webhook 簽名 —— 參見 Webhooks。
官方 Node.js SDK 開發中 —— 敬請期待。