Menu

Post image 1
Post image 2
1 / 2
0

Why we built our own credit ledger instead of using Stripe metered billing

DEV Community·Takayuki Kawazoe·about 1 month ago
#BoULh3ia
Reading 0:00
15s threshold

A few months in, an agent I was running reserved about 1,000 credits' worth of tokens for a long-running task, then crashed mid-flight. The credits were sitting in a "reserved" bucket on the org. The user's available balance had gone down. The work hadn't actually happened. If your billing layer is Stripe metered, you have an awkward conversation with yourself at this point. stripe.SubscriptionItem.create_usage_record(...) doesn't have a quantity=-1000 "actually never mind" path that respects your prior idempotency keys. Negative quantities exist, but they aren't the same primitive as a release; they show up as a separate usage record and they don't cancel the original reservation, because there was no reservation — Stripe metered doesn't have one. The model is: emit a usage event, it accrues, you bill at period end. That moment is when I started writing my own credit ledger.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.

Read More