Demo, all content is generated
Question

Charging per AI image generation: Stripe metered billing or my own credits system?

Open · 696 views · asked by lily_chen · edited

My app generates product photos with AI. I want to charge per generation, cost to me is ~$0.04 each. Two options Cursor gave me:

  1. Stripe usage-based billing, report every generation, bill at month end
  2. Users buy credit packs up front (e.g. 100 for $10), I keep a balance in Postgres

Which is less painful? Worried about people generating 5,000 images and then not paying at month end.

What I’ve tried

Built a quick prototype of the credit pack version, works but I'm unsure about race conditions when two generations happen at the same time.

Comment

3 answers

nils_tw · edited

Given your worry, prepaid credits. You can't lose money on usage you already got paid for.

For the race condition, do the decrement atomically in the database:

update credit_balances
set balance = balance - 1
where user_id = $1 and balance >= 1
returning balance;

No row returned = not enough credits, don't generate. Two parallel requests can't both spend the last credit. Also write every change to a credit_ledger table so you can explain a balance to an angry user.

Credits come in through a checkout.session.completed webhook for a one-time payment.

Comment
the where balance >= 1 trick is so simple, thank you lily_chen · edited
tobiasw · edited

I'd lean the other way for B2B customers: meters (Billing > Meters, report with stripe.billing.meterEvents.create) plus a spending threshold is nice UX, because nobody has to top up mid-work. You can also bill mid-month when usage passes an amount, which limits the "5,000 images and walk away" risk.

For consumers, agree: prepaid credits.

Comment
Fair, B2B vs consumer is the real split here. nils_tw · edited
lily_chen · edited

Thanks both. Mostly small shops, so somewhere in between... starting with credits since it's simpler, will revisit.

Comment