ShipStack
Back to blog
ArchitectureJanuary 26, 20256 min read

How to Implement Usage-Based Billing With API Analytics

Usage-based billing aligns your revenue with the value you deliver. Here's how to implement it with API metering, tier enforcement, and Stripe integration.

Why usage-based billing wins

Traditional SaaS pricing (flat monthly fee) is being replaced by usage-based models. Companies like Twilio, Stripe, AWS, and OpenAI charge based on actual consumption. The advantages are clear:

- Lower barrier to entry — Customers pay nothing until they use the product. Free tiers convert better when there's no upfront commitment. - Revenue scales with value — Heavy users pay more, light users pay less. This aligns your incentives with customer success. - Natural upselling — As customers grow, they automatically move to higher tiers. No awkward sales conversations needed. - Fairer pricing — Customers feel they're paying for what they use, not subsidizing others.

The challenge: implementing usage tracking, tier enforcement, and billing integration requires infrastructure that most startups don't have time to build.

Metering API usage

The foundation of usage-based billing is accurate metering — counting every API call per user or tenant. There are three approaches:

1. Application-level logging: Increment a counter in your database on every API request. Simple but adds latency to every request.

2. Async event streaming: Log API events to a queue (Redis, Kafka) and process them asynchronously. No added latency but more infrastructure to manage.

3. Built-in platform metering: Use a platform that tracks API usage automatically. ShipStack's usage analytics track every API call per tenant, per capability (auth, database, storage), with response times and error rates — no custom code needed.

For most startups, option 3 is the fastest path. You get production-grade metering without building or maintaining the infrastructure.

Designing pricing tiers

Usage-based doesn't mean no tiers. The best SaaS products combine usage-based pricing with tier boundaries:

- Free: 5,000 API calls/month, 1 project, community support. - Launch ($19/mo): 100,000 calls/month, 3 projects, email support. - Scale ($49/mo): 1,000,000 calls/month, unlimited projects, priority support. - Enterprise (custom): Unlimited calls, custom SLA, dedicated support.

Each tier includes a base allocation. Overage can be handled by blocking requests (return 429), allowing overage at a per-call rate, or auto-upgrading to the next tier.

ShipStack's rate limiting enforces these tiers at the infrastructure level. When a tenant exceeds their allocation, the API returns 429 automatically.

Integrating with Stripe

Stripe is the standard for SaaS billing. Here's how to connect usage metering to Stripe:

1. Create Stripe Products and Prices for each tier. Use Stripe's metered billing mode for usage-based components. 2. Report usage to Stripe at the end of each billing period. Query your metering data (from ShipStack's analytics or your database) and report it via Stripe's Usage Records API. 3. Handle webhooks — Listen for invoice.paid, invoice.payment_failed, and customer.subscription.updated events. Update user tier metadata in your database accordingly. 4. Enforce access — On each API request, check the user's current tier and usage against their limits. ShipStack handles this automatically for its built-in tiers.

The key insight: metering and billing should be decoupled. Meter everything in real-time. Bill periodically (monthly). This way, usage tracking never blocks the user experience.

Showing usage to customers

Transparency builds trust. Show customers their usage with a simple dashboard:

- Current period usage — API calls made this month vs. their tier limit. - Usage by capability — Breakdown by auth, database, and storage calls. - Historical trends — Month-over-month usage to help customers predict costs. - Projected invoice — Estimated cost based on current usage rate.

With ShipStack, you can query per-tenant usage analytics through the API and render this data in your frontend. No custom analytics infrastructure needed.

Usage visibility has a counterintuitive benefit: it increases willingness to pay. When customers can see exactly what they're getting for their money, they're less likely to churn and more likely to upgrade.

billingusage-basedSaaSStripeAPI analytics

Ready to ship your backend?

Free to start. No credit card required. Connect your first provider in under 5 minutes.

Get Started Free