SDKs
Node.js / TypeScript
Thunderbit Open API のための Node.js イディオムなパターン
Thunderbit API は組み込みの fetch(Node 18+)で動くので、SDK は不要です。HTTP/2 や大規模な接続プーリングが必要なら undici や axios に乗り換えましょう。
Configure
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());ハンドラ側で Webhook 署名を検証してください —— Webhooks を参照。
公式 Node.js SDK は開発中です —— もう少しお待ちください。