Webhook callbacks
Terminal-state callbacks — triggers, payload, signature verification, and retries.
This page describes the gateway's real webhook contract (as opposed to the "illustrative examples" in earlier drafts). Fields and behavior here are authoritative.
Webhooks free you from polling: when a task reaches a terminal state, the platform pushes the result to your endpoint.
Enabling it
Pass a webhook field (a base URL) when you submit on Generate images:
On a terminal state the platform POSTs to <webhook>/callback (the /callback suffix is appended automatically). The example above calls back to https://your-app.example.com/hooks/jiufeng/callback.
Trigger rules
| Situation | Callback? |
|---|---|
Task succeeds (completed) | Once |
Task fails (failed) | Once |
Intermediate states (pending / processing) | No |
| Task refunded on timeout | No (poll these via Query tasks) |
A callback is sent only on terminal states, once each. Your endpoint should be idempotent (the same id may arrive more than once due to retries), and you shouldn't rely on the callback alone — keep a polling fallback for success.
Payload
The callback body is the Query tasks data object itself, without the { code, data } envelope:
On failure, status is failed with error: { message, type, param, code }.
Signature verification
Each callback carries a request header:
webhook_secretis an account-level setting (configured in the console) — not a request parameter.- When the secret is empty, the platform sends no signature header.
- Compute HMAC-SHA256 over the raw body bytes (not a re-serialized parse of the JSON), then compare against the header value in constant time.
Minimal receiver
Retry policy
| Your endpoint returns | Platform behavior |
|---|---|
2xx | Ack; done, no further pushes |
4xx (except 429) | Treated as a permanent failure; no retry |
5xx / timeout / network error / 429 | Backoff retry: 10s → 30s → 60s, up to 3 times; then dead-lettered |
- Each callback request times out at 10s — return quickly (do heavy work asynchronously; reply 200 first).
- For reliable delivery, ack fast and move downloading / re-hosting into a background job.