How I Handle Retries and Timeouts in an AI Image Generator
I built gptimage26gen, a browser tool that turns text prompts into PNG images, looping GIFs, and SVG graphics. All three formats share the same job workflow. One of the trickiest parts was deciding what to do when a request times out and the app can't tell whether the provider accepted it.
Give the job a life outside the browser
The app stores each job in Cloudflare D1. Once the server accepts a request, the browser checks the job's status using its ID. Refreshing the page just starts another status check. The job can keep running and the user can come back to the same result.
Make a repeated click safe
Before the user confirms a generation, the server returns a quote. On confirmation, it creates the job and reserves credits in one transaction. The request includes an idempotency key, so submitting the same request again can return the existing job without reserving credits twice.
Keep an unknown result visible
If the provider call times out after submission, the job can move to provider_unknown. The provider might already be processing the request, so the worker stops automatic retries and leaves the job for reconciliation. That makes an uncertain outcome visible and avoids sending a second potentially billable request.
The next thing I'd like to improve is how this state is explained to users. If you've built a similar workflow, what do you show someone while you're still checking whether their request went through?
This draft was written with AI assistance.