Instead of polling for task status, configure a webhook to receive notifications when events occur. ModelHunter.AI will POST a JSON payload to your URL.
Configured webhooks (registered via POST /api/v1/webhooks) include X-Webhook-Signature for verification and support automatic retries.
Per-job webhooks (via webhookUrl in a generation request) do not include X-Webhook-Signature (no shared secret), but include additional headers: X-Webhook-Event (e.g. task.completed) and X-Job-ID.
Configured webhooks include an X-Webhook-Signature header. Verify it to ensure the request is authentic.The signature is computed as HMAC-SHA256(timestamp + "." + body, secret).
import crypto from "crypto";function verifyWebhookSignature(req, secret) { const timestamp = req.headers["x-webhook-timestamp"]; const signature = req.headers["x-webhook-signature"]; const body = JSON.stringify(req.body); const expected = crypto .createHmac("sha256", secret) .update(`${timestamp}.${body}`) .digest("hex"); const expectedSignature = `sha256=${expected}`; if (signature !== expectedSignature) { throw new Error("Invalid webhook signature"); } // Reject timestamps older than 5 minutes const age = Math.floor(Date.now() / 1000) - parseInt(timestamp, 10); if (age > 300) { throw new Error("Webhook timestamp too old"); } return true;}