Skip to content

Webhooks

Background jobs can notify your server when they finish. Set webhook_url on a job, or set a default URL on your account. You can always poll GET /optimize/jobs/{id} instead; honor the Retry-After header.

Event When
job.completed A job finished and the result is ready
job.failed A job failed. Failed jobs are not billed

The body carries id, type, created_at and data (job_id, status, units_billed, or error). It never contains the result: fetch it with GET /optimize/jobs/{id}.

Every delivery carries a header:

X-Signature: t=1764180000,v1=5257a869...

v1 is an HMAC-SHA256 with your account’s webhook secret. Compute it over the timestamp, a dot and the raw request body, compare in constant time and reject old timestamps. The API reference is authoritative if the exact signed string changes before launch.

import { createHmac, timingSafeEqual } from 'node:crypto';
export function verify(rawBody, header, secret, toleranceSeconds = 300) {
const parts = Object.fromEntries(header.split(',').map((p) => p.split('=')));
if (Math.abs(Date.now() / 1000 - Number(parts.t)) > toleranceSeconds) return false;
const expected = createHmac('sha256', secret).update(`${parts.t}.${rawBody}`).digest('hex');
const a = Buffer.from(expected);
const b = Buffer.from(parts.v1 ?? '');
return a.length === b.length && timingSafeEqual(a, b);
}

If your endpoint does not answer with a 2xx status, we retry up to 6 times with exponential backoff over 24 hours. Make your handler idempotent: the same event can arrive more than once.

The dashboard keeps a delivery log for 7 days.