Most usage-based AI products get billing wrong in the same way. They meter in tokens or API calls, a unit the customer never thinks in, and the balance drifts out of sync the moment a user has both a subscription and a top-up pack.
The problem
A research summarisation product needed to charge customers in a unit they actually understood: words. A single balance also had to stay accurate whether the credits came from a subscription or a one-off purchase. On top of that, large PDFs take real time to process, and a blank screen during that wait kills trust.
The approach
I metered consumption in the unit the customer understands, words, and decremented credits against one unified balance regardless of where they came from. Document processing runs entirely in the background, with progress surfaced to the user live instead of a blank loading state.
Stack: Ruby on Rails 7, Hotwire, Sidekiq, OpenAI, Stripe, PDF processing, Postgres
Result: Usage-based billing that stays tied to real model cost, one balance across subscriptions and one-time packs, and live progress during background processing.
The lesson: billing logic is a production system too. It fails silently, and customers notice a wrong balance faster than they notice a wrong AI answer.
Full breakdown → https://farzamazhar.com/#work