AI Artwork SaaS
Prepaid credits that track real model costs
Generate, edit and export production-ready artwork, paid for with prepaid credits.
The problem
Image models charge per call, and the cost changes with the model and the image size. A flat monthly plan either loses money on heavy users or overcharges light ones. The product needed billing that follows real usage and never charges anyone twice.
What we built
- An Astro app on Cloudflare Workers with an interactive React editor to generate, adjust, edit, filter and export images.
- Generation and editing jobs routed to OpenAI and Gemini image models.
- Prepaid credit packs sold through a hosted checkout, with a wallet and ledger in Cloudflare D1 that records every top-up and every spend.
- Idempotent payment webhooks: a retried event can never credit an account twice.
- Generated files stored in R2 behind signed download links, rate limiting in KV, and sign-in with Clerk.
Decisions that mattered
Credits instead of a subscription
Customers pay for what they generate, so the price tracks the real model cost and nobody subsidises anybody else.
A ledger, not a balance field
Every change to a balance is its own row. Support questions, refunds and reconciliation with the payment provider become a query, not an investigation.