
Run AI generation from a short-lived serverless route by persisting intent, handing submission to durable work, and returning an operation identifier promptly. Do not spend the request's entire execution window polling a video to completion. A route deadline and the remote task's lifecycle are different boundaries.
The Imagild API already separates generation acceptance from task polling and authenticated download. Your deployment must preserve those identities across function shutdown, cold starts and retries.
Key Takeaways
- Persist a recoverable operation before crossing the provider network boundary.
- Use a durable queue or outbox worker rather than an untracked post-response promise.
- Treat host time limits as local constraints, not evidence that generation failed.
Draw the execution boundaries first
A portable design has three stages:
| Stage | Work performed | Durable output |
|---|---|---|
| Web request | Authenticate, validate and approve spending | Local operation plus submission event |
| Submission worker | Send one saved request to Imagild | Provider task ID or uncertain-submission record |
| Reconciliation worker | Read task state and obtain approved output | Observed result, usage and download record |
These stages can use different infrastructure. They do not require the browser to stay connected, and they do not require an Imagild webhook that the current API does not implement.
fal's asynchronous queue documentation illustrates the general separation of submission from status and result retrieval. Its cancellation and delivery features are not Imagild endpoints.
Do not confuse post-response work with durable work
In Next.js 16.3.0, the locally installed documentation states that after schedules post-response work within the route's platform duration. That can be useful for short side effects, but it is not an unlimited worker lifetime.
Avoid this design for the sole copy of a paid operation:
return accepted response
start an untracked promise
submit generation
keep polling in that same function
hope the process remains available
Instead, commit the operation and a durable outbox event before returning. A separate dispatcher can discover the event even if the web function stops immediately afterward.
Increasing a host timeout can change how long a request waits. It does not replace persistence, guarantee job completion or turn a local abort into a provider cancellation.
Store enough for each crash boundary
Before submission, retain the exact generation body and a stable Idempotency-Key. After acceptance, retain data.id. Keep those fields attached to the owning application user and approved point quote.
If the worker stops after sending a POST but before saving its response, recover with the original key and unchanged parsed parameters. If a task ID is already saved, read that task. Do not make a new key merely because the worker received the same queue event twice.
A current image request uses only its supported model, prompt, resolution and optional owned reference selector. Video adds its supported duration, ratio and enhancement settings. A local timeout, deployment region or queue name belongs in your application record, not in the strict provider JSON.
Schedule short reconciliation visits
Let a worker read existing task state, save the observation and schedule the next visit using poll_after_seconds, currently five seconds. Coordinate across the account's current read allowance rather than polling every task from every browser tab.
If a visit ends because the host shuts down, the operation should remain resumable. A remote unknown result needs reconciliation; a failed task and a successful task have different usage outcomes. The failed-job guide is useful context for those branches.
Validate shutdown recovery before rollout
Use mocks to stop execution after each durable boundary: after local commit, after provider acceptance, and after task-ID persistence. Restart a dispatcher and check that the original operation resumes with the same parameters.
Keep secrets in server configuration and authorize the local status endpoint for each user. OWASP's REST guidance explains endpoint access controls independently of the framework.
Active membership and points remain required; short-lived hosting does not alter that contract. Use the points planning guide for the spending confirmation. This design reduces dependence on one request's lifespan without claiming a distributed exactly-once guarantee.
Related tasks
- What Should You Check Before Retrying a Failed Image or Video Job?
- Imagild Points, Resolution and Jobs: Plan a Creation Before You Spend
Sources and scope
- Imagild API console: Active-member access, supported media request fields, idempotency, asynchronous task records and authenticated downloads; checked against the 2026-10-28 relay contract.
- Next.js after reference: Post-response work remains subject to platform route duration; not evidence of a durable unlimited background worker.
- fal Queue API: General asynchronous submission/status/result separation; fal cancellation and delivery features are not Imagild endpoints.
- OWASP REST Security Cheat Sheet: Endpoint authorization and server-side credential handling; individual application-customer ownership remains the integrator's responsibility.
Product instructions were checked against the current Imagild API contract and the public model catalog. Code, budgets and acceptance checks are illustrative; this article does not claim a new paid generation test, an uptime measurement, a search-volume study or a ranking of AI citations.
Prepared by Imagild Editorial, the company editorial team responsible for these guides. AI assisted research and drafting. This is documentation-based guidance with proposed examples, not a claim of hands-on testing or an independent product review. Report a correction.
Cover: Original Imagild product screenshot captured on 28 October 2026; model availability and prices may change. This image is not an API response or a performance benchmark.