Skip to content
会nokai.studio

Webhooks

Webhooks are how nokai.studio tells your server about job completions, failures, and credit events -- without you polling.

How it works

  1. Register an HTTPS endpoint via POST /v1/webhook-endpoints.
  2. Specify which events you want: job.completed, job.failed, credits.low_balance, credits.topped_up.
  3. The API server POSTs a signed JSON body to your URL for each matching event.
  4. Respond with any 2xx. Non-2xx or timeouts trigger retries.

Every event is recorded in the delivery log before delivery is attempted. Query it via GET /v1/webhook-deliveries.

Signature

Every webhook carries signing headers:

X-Webhook-Timestamp: 1748563200
X-Webhook-Signature: <base64_hmac>
X-Webhook-Event: job.completed

The signature is base64(HMAC_SHA256(signing_secret, "<taskId>.<timestamp>")), where <taskId> is data.taskId and <timestamp> is the X-Webhook-Timestamp value. Verify it before trusting the payload. Full how-to: Webhooks -> Signature verification.

Retries and backoff

Failed deliveries (non-2xx or timeouts) are retried with exponential backoff:

AttemptDelay
1 (immediate)0s
2~10s
3~60s
4~5m
5~30m
6~2h
After attempt 6gives up

Total retry budget: ~2.5 hours.

Idempotency

Every event carries an event_id (UUID) that is stable across retries. Use it as a dedupe key:

async function handleWebhook(req) {
  const { event_id } = req.body;
  if (await alreadyProcessed(event_id)) return res.sendStatus(200);
  // do work
  await markProcessed(event_id);
}

Payload structure

All events share the same envelope:

{
  "api_version": "v1",
  "event_id": "uuid",
  "event": "job.completed",
  "customer_id": "uuid",
  "created_at": "2026-05-29T12:00:00Z",
  "data": { ... }
}

See Webhooks -> Payloads for per-event data shapes.

Filtering by provider

When registering an endpoint, set provider_filter to receive events only for jobs run by a specific generation provider. Leave null to receive all.