DEV Community

visiohex
visiohex

Posted on • Originally published at img2gen.com

I built Img2Gen, a GPT Image 2 studio on Cloudflare Workers

I recently built Img2Gen, a focused web studio for GPT Image 2 generation.

The idea was simple: I wanted something more practical than a single prompt box. For real creative work, I often need to try multiple aspect ratios, upload reference images, generate several variants, download the results, and keep a history of what worked.

So Img2Gen supports:

  • Text-to-image generation
  • Reference-image edits with up to 5 uploaded images
  • 1, 2, or 4 outputs per request
  • Multiple aspect ratios
  • Low, medium, and high quality modes
  • Daily free generations
  • Credit-based paid usage
  • Generation history and downloads
  • Automatic refunds when a generation fails

The Stack

The app is built with:

  • TanStack Start
  • React 19
  • Cloudflare Workers
  • Cloudflare D1 with Drizzle ORM
  • Cloudflare R2 for generated image storage
  • Better Auth
  • Stripe / Creem for payments
  • A server-side GPT Image 2 generation provider

I wanted the whole thing to run close to the edge, avoid a traditional server, and keep the architecture small enough that I could iterate quickly.

Why Cloudflare Workers?

Image generation itself is slow compared with a normal web request, so the main app has to handle queued jobs, polling, persistence, and failures cleanly.

The flow looks roughly like this:

  1. User submits a prompt and optional reference images
  2. The server validates the request and checks moderation
  3. Free daily usage or credits are reserved
  4. A generation job is submitted to the provider
  5. The client polls for status
  6. Successful images are downloaded, moderated, and persisted to R2
  7. The generation record is saved in D1
  8. Credits are refunded if the job fails

The hardest part was not the UI. It was making the generation workflow feel reliable when the underlying job can take a while or fail halfway through.

Credit Handling

I ended up using a credit model because image quality and output count change the cost.

Currently:

  • Low quality: 1 credit per image
  • Medium quality: 4 credits per image
  • High quality: 16 credits per image

Free users get daily generations, and paid users can use monthly credits or credit packs.

One small detail I cared about: failed generations should not silently burn credits. If a job fails after credits are reserved, the system refunds them automatically.

Reference Images

Reference-image editing was one of the main reasons I built this.

Img2Gen accepts PNG, JPG, and WebP references, up to 5 images per request. This makes it useful for product shots, ad creatives, portraits, style exploration, and iterative edits where you want the output to stay anchored to existing visuals.

What I Learned

A few takeaways from building it:

  • AI image apps need good job recovery, not just good prompts.
  • Credit systems need to be boring and predictable.
  • Storing generated outputs matters because provider URLs are not always a long-term product experience.
  • A focused workflow can be more useful than exposing every possible model setting.
  • Edge/serverless architectures work well here, but long-running generation flows need careful state design.

Try It

You can try it here:

https://img2gen.com

I would love feedback from other builders, especially on:

  • Whether the generation flow feels clear
  • Whether the credit model is understandable
  • What reference-image workflows you would expect from a tool like this
  • Any architecture suggestions for long-running AI generation jobs on serverless platforms

Top comments (0)