指南

Webhooks

接收批量任务完成通知

对于超过一分钟的批量任务,Webhook 比轮询更省、更快。任务进入终态时,Thunderbit 会向你的 URL 发起 POST。

在提交时配置

{
  "urls": ["https://example.com/page1"],
  "webhook": {
    "url": "https://your-server.com/api/webhook/distill",
    "secret": "whsec_your_secret_key",
    "headers": { "X-Custom-Auth": "your-token" }
  }
}

Payload

{
  "id": "batch_abc123",
  "status": "COMPLETED",
  "total": 50,
  "completed": 49,
  "failed": 1,
  "completedAt": "2026-04-26T10:00:00Z"
}

Payload 刻意保持精简 —— 收到回调后再通过 GET /batch/distill/{id} 拉完整结果。

签名校验

设置了 secret 时,每次投递都会带上 X-Webhook-Signature: sha256=<hex>。用 HMAC-SHA256 校验。

import hmac, hashlib

def verify(raw_body: bytes, signature: str, secret: str) -> bool:
    expected = "sha256=" + hmac.new(
        secret.encode(), raw_body, hashlib.sha256
    ).hexdigest()
    return hmac.compare_digest(expected, signature)

生产环境永远不要信任未签名的 Webhook。

重试行为

  • 非 2xx → 5 次重试,指数退避:10s、30s、2m、10m、30m
  • 单次投递超时:15s
  • 全部重试失败后,任务在我们这边仍是已完成 —— 你的端点必须是幂等的

本页正在补充调试技巧 —— 敬请期待。