SDKs

Bash / cURL

適合臨時任務的 shell 一行命令與 jq 流水線

適合快速檢查、CI 腳本、或把 markdown 直接接到下一個工具。curl 搭配 jq 就能切片回應。

設定

export THUNDERBIT_API_KEY="..."
export API="https://openapi.thunderbit.com/openapi/v1"

Distill 一個頁面

curl -sX POST "$API/distill" \
  -H "Authorization: Bearer $THUNDERBIT_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"url": "https://thunderbit.com/playground"}' \
  | jq -r '.data.markdown'

直接接到檔案或下一個工具:

curl -sX POST "$API/distill" \
  -H "Authorization: Bearer $THUNDERBIT_API_KEY" \
  -d '{"url": "'"$1"'"}' \
  | jq -r '.data.markdown' > out.md

Extract 結構化資料

curl -sX POST "$API/extract" \
  -H "Authorization: Bearer $THUNDERBIT_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "url": "https://example.com/product/iphone-15-pro",
    "schema": {
      "type": "object",
      "properties": {
        "name":  { "type": "string" },
        "price": { "type": "number" }
      },
      "required": ["name", "price"]
    }
  }' \
  | jq '.data'

Batch + 輪詢

從 shell 跑臨時批次:

JOB=$(curl -sX POST "$API/batch/distill" \
  -H "Authorization: Bearer $THUNDERBIT_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"urls": ["https://example.com/p1", "https://example.com/p2"]}' \
  | jq -r '.data.id')

while :; do
  STATUS=$(curl -s "$API/batch/distill/$JOB" \
    -H "Authorization: Bearer $THUNDERBIT_API_KEY" \
    | jq -r '.data.status')
  echo "$STATUS"
  [[ "$STATUS" == "COMPLETED" || "$STATUS" == "FAILED" ]] && break
  sleep 10
done

正式環境請優先用 Webhook,不要輪詢 —— 參見 Webhooks

URL 清單驅動的批次

xargs -a urls.txt -I {} echo '"{}"' \
  | paste -sd, - \
  | xargs -I {} curl -sX POST "$API/batch/distill" \
      -H "Authorization: Bearer $THUNDERBIT_API_KEY" \
      -H "Content-Type: application/json" \
      -d '{"urls": [{}]}'