AI Image Generation API Webhooks: Signatures, Deduplication and Recovery
Use Apiframe v2 as a concrete example to separate generation success from webhook delivery and image availability, verify raw-body signatures, and recover missed or repeated notifications.
·

A completed webhook does not mean your application has a usable image. Generation may succeed while notification delivery fails. A notification may also be safely stored while the image download is still timing out. For AI image generation API webhooks, keep generation state, notification-processing state, and local asset availability separate.
The protocol example here follows the Apiframe webhook documentation retrieved on December 2, 2026, including its v2 job interface. The page's update date is unknown; check the current contract before implementation. The storage and recovery patterns below are recommendations, not reported test results. They concern hosted generation, not local ComfyUI node execution.
What an event establishes—and what remains to do
Apiframe accepts webhookUrl and webhookEvents in a generation request and sends HTTP POST notifications. Its documented events are progress, completed, and failed; payloads include jobId. Persist the provider job ID against your business record as soon as you obtain it, rather than waiting for the completion callback to create that association.
| Signal | Documented meaning | Recommended application action |
|---|---|---|
progress | The progress percentage changed | Update presentation; do not deliver an asset |
completed | Generation succeeded; a result object is included | Persist result references and schedule asset retrieval |
failed | Generation failed; error information is included | Store the error and stop waiting for this generation |
| Download success or failure | Not one of these webhook event types | Track local asset availability separately |
The Apiframe page also documents webhookStatus values of pending, delivered, and failed. A failed delivery is not a failed generation. A delivered notification does not prove your background worker has downloaded or accepted the image.
Verify the received bytes, not reconstructed JSON
Apiframe documents HMAC-SHA256 verification through X-Webhook-Signature. Following the algorithm and examples in the retrieved page:
1. Read the original API key from secure server configuration. Hash it with SHA-256 and use the hexadecimal string as the signing secret.
2. Capture the raw request-body bytes before JSON middleware transforms them.
3. Compute HMAC-SHA256 over those bytes. The documented examples prefix the hexadecimal digest with sha256=.
4. Reject missing or malformed signatures. Check the expected length before a constant-time comparison, and do not change business state if verification fails.
There is a relevant inconsistency in the source: its prose requires the raw request body, while its Node handler example uses JSON.stringify(req.body). Do not copy that reserialization step into raw-body verification. Whitespace or key-order changes can change the signature. Preserve the original bytes explicitly, and keep API keys and signing secrets out of logs.
This contract is not portable between providers. Replicate's verification documentation uses webhook-id, webhook-timestamp, and webhook-signature; its signed content is id.timestamp.body, and timestamp validation is part of replay protection. Neither its headers nor Apiframe's key derivation should be transplanted into the other integration. The retrieved Apiframe page does not establish an equivalent timestamp protocol. A valid signature does not prove an event has never been processed before.
Deduplicate effects without discarding later events
After verification, parse and validate the event, required fields, and job ownership. Persist the event and the work to perform before acknowledging it; let a background worker handle downloads. Apiframe recommends returning 200 within a few seconds, but a fast acknowledgment should not precede reliable storage.
A single “processed” flag keyed only by jobId is too coarse. Processing a progress event must not suppress completion. Separate two concerns:
- Delivery deduplication: Prefer a documented unique message identifier when available. The retrieved Apiframe page does not provide one. A digest of the verified raw payload, scoped by provider, account, job, and event type, can identify identical payloads; it is not a provider-issued message ID.
- Business idempotency: Use a database uniqueness rule or atomic state transition to prevent concurrent callbacks from scheduling the same delivery effect twice. Commit the event and its work record together, or use an equivalent reliable mechanism.
For an illustrative test, send progress: 45, two copies of completed, and then a delayed progress: 80 for one job. Only one result-processing operation should be created, and late progress must not move the job back to processing. If conflicting terminal events appear, reconcile the original job rather than choosing whichever arrived last. This is a test scenario, not a claim about provider ordering guarantees.
Recover the original job, then recover its download
According to Apiframe's retry documentation, terminal events are retried up to 10 times with exponential backoff starting at five seconds. Progress events are best-effort with one attempt. Missing progress is therefore not necessarily an error, and a missing completion notification is not a reason to submit generation again.
Schedule reconciliation for records that remain unresolved beyond your business waiting threshold. Query GET /v2/jobs/:id using the saved provider ID. The page says the result object matches the callback result, with its shape depending on the job modality. Feed lookup results through the same state-transition and idempotent-delivery logic as callbacks so the recovery path cannot create a second download operation. Choose lookup intervals from your deadline and the current API limits, not a universal polling interval.
If generation succeeded but asset retrieval failed, retain the successful generation state and retry retrieval only. Apply download timeouts, size limits, expected file-type checks, and explicit policies for destination domains, redirects, and target networks. Do not replay paid generation to fix a download error. Do not assume result URLs remain available indefinitely: the retrieved page provides no such lifetime guarantee.
In a test environment, inject duplicate completions, late progress after a terminal event, a fully missed notification, and a failed first download. Inspect event records, business state, and download-work counts—not just HTTP 200 responses. The properties to verify are a reconcilable original job, no terminal-state regression, no repeated delivery effect, and no new generation caused by a download failure. These are proposed checks, not measured outcomes.
Check the contract before choosing the integration
Confirm the signing algorithm, raw-body handling, event identity, terminal-state rules, delivery retries, original-job lookup, and result-URL lifetime. Other providers may answer these questions differently; the Apiframe example is not a substitute for their contracts.
For programmatic image generation in a business system, see InkRoom's image API introduction and integration entry. That entry does not establish support for the webhooks, signatures, retries, or reconciliation mechanisms described here. Check the current documentation and account configuration against your recovery requirements first.
Submission-side concurrency, 429 responses, and uncertain acceptance are a separate concern. Continue with AI image API rate limits and safe retries for that boundary.
Related articles and cases
- ComfyUI Local API Workflow: Submit, Track Progress and Retrieve Images
Start with a workflow that already runs locally, capture its real request, submit through /prompt, observe /ws, inspect /history/{prompt_id}, and retrieve images through /view.
- ControlNet Canny: Using Edge Maps to Guide Composition
Inspect broken outlines and unwanted edges, prepare a Canny conditioning image, check the documented SD 1.5 pairing, and plan controlled composition comparisons. SDXL pairing and conditioning-strength instructions remain outside the available evidence.
- AI Image API Rate Limits: Concurrency, 429s, and Uncertain Submissions
Request rates, image allowances, and concurrency are separate constraints. Build retries around submission state, with conditional Retry-After handling, bounded backoff, and a recovery path that does not blindly replay paid work.