SDKs
PHP
Thunderbit Open API 的 PHP 地道寫法
用 Guzzle。一行 Composer 安裝完成;支援 PHP 8.1+。
安裝
composer require guzzlehttp/guzzle設定
<?php
require 'vendor/autoload.php';
use GuzzleHttp\Client;
$api = new Client([
'base_uri' => 'https://openapi.thunderbit.com/openapi/v1/',
'headers' => [
'Authorization' => 'Bearer ' . getenv('THUNDERBIT_API_KEY'),
'Content-Type' => 'application/json',
],
'timeout' => 60,
]);Distill 一個頁面
$res = $api->post('distill', [
'json' => ['url' => 'https://thunderbit.com/playground'],
]);
$data = json_decode($res->getBody(), true);
echo $data['data']['markdown'];Extract 結構化資料
$res = $api->post('extract', [
'json' => [
'url' => 'https://example.com/product/iphone-15-pro',
'schema' => [
'type' => 'object',
'properties' => [
'name' => ['type' => 'string'],
'price' => ['type' => 'number'],
],
'required' => ['name', 'price'],
],
],
]);
$data = json_decode($res->getBody(), true)['data'];Batch + Webhook
$job = json_decode($api->post('batch/distill', [
'json' => [
'urls' => ['https://example.com/page1', 'https://example.com/page2'],
'webhook' => [
'url' => 'https://your-server.com/webhook',
'secret' => getenv('WEBHOOK_SECRET'),
],
],
])->getBody(), true);
error_log('Batch submitted: ' . $job['data']['id']);在你的 handler 裡驗證 Webhook 簽名 —— 參見 Webhooks。
官方 PHP SDK 開發中 —— 敬請期待。