SDKs

Bash / cURL

임시 작업을 위한 셸 원라이너와 jq 파이프라인

빠른 점검, CI 스크립트, 또는 markdown 을 다른 도구로 바로 파이프할 때 유용합니다. curljq 를 짝지어 응답을 잘라내세요.

설정

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 + 폴링

셸에서 임시 batch 실행에 사용하세요.

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 목록 기반 Batch

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": [{}]}'