GEMINI LABJP
NANOLITE — Nano Banana 2 Lite is here: Google's fastest and most cost-efficient Gemini Image model, made for running lightweight image generation cheaplyOMNIFLASH — Gemini Omni Flash is in public preview, a natively multimodal model that lets enterprises and developers build custom, dynamic video workflowsAGENTS — Managed Agents expand with background: true for async server-side runs and polling, remote MCP server integration, and refreshing credentials across interactionsMEMORY — The Memory Bank IngestEvents API is generally available, decoupling event ingestion from memory generation so you can stream content continuouslyTHROUGHPUT — Provisioned Throughput now lets you submit up to seven pending orders for the same model and regionDEPRECATE — Image generation models shut down on August 17, and the Grok 4.1 family on the Gemini Enterprise Agent Platform on August 20NANOLITE — Nano Banana 2 Lite is here: Google's fastest and most cost-efficient Gemini Image model, made for running lightweight image generation cheaplyOMNIFLASH — Gemini Omni Flash is in public preview, a natively multimodal model that lets enterprises and developers build custom, dynamic video workflowsAGENTS — Managed Agents expand with background: true for async server-side runs and polling, remote MCP server integration, and refreshing credentials across interactionsMEMORY — The Memory Bank IngestEvents API is generally available, decoupling event ingestion from memory generation so you can stream content continuouslyTHROUGHPUT — Provisioned Throughput now lets you submit up to seven pending orders for the same model and regionDEPRECATE — Image generation models shut down on August 17, and the Grok 4.1 family on the Gemini Enterprise Agent Platform on August 20
Articles/API / SDK
API / SDK/2026-04-26Advanced

Gemini API × Stripe — Production Usage-Based Billing for Indie AI SaaS

A complete guide to building a usage-based billing system for your Gemini API SaaS using Stripe Metered Billing and webhooks — production patterns included.

Gemini API192Stripe10SaaS11Billing2Webhook3Metered BillingProduction32

Premium Article

When you're building a SaaS on top of the Gemini API as a solo developer, the first thing you stall on is usually billing. I love that some readers stick around after starting on the free tier — but letting power users burn more in API costs than they pay you is not a sustainable structure to leave in place.

A pure flat subscription means a person who uses 10K tokens a month pays the same as someone who uses 10M. A pure usage-based plan, on the other hand, scares potential users away because they can't predict their bill. Neither extreme works for an indie AI SaaS.

In this article, I'll walk through the hybrid model I actually run in production — a flat base subscription plus metered overage — implemented with the Gemini API and Stripe in a way that survives real traffic. We'll cover webhooks, idempotency, accurate token metering, and tier-based feature gating, all the way through the operational realities you'll bump into the moment you go live.

Choosing usage-based billing for an indie AI SaaS

Before any code, let's settle when usage-based billing is actually the right call. From my own experience, a pure flat-rate model breaks down quickly when LLMs like Gemini sit on the backend.

The reason is simple: usage of an AI-powered app varies by 1,000× or more across users. Light users do dozens of requests a month; heavy users do hundreds of thousands. If you try to absorb that with a single monthly fee, you're forced into one of two bad choices: charge light users too much, or run your heavy users at a loss.

The hybrid model I currently run looks like this.

  • Free: Up to 50,000 tokens/month at no cost — an onboarding allowance to keep new users from bouncing
  • Pro (¥980/mo): 500,000 tokens included; overage at ¥150 per 100,000 tokens
  • Team (¥4,800/mo): 5,000,000 tokens included; overage at ¥100 per 100,000 tokens

The strength of this model is that it gives users a predictable monthly base while still recovering cost from heavy users. In Stripe, you can express this as a single subscription with two subscription items: one flat Price, one Metered Price. They roll up into one invoice each month.

System architecture — from a token to an invoice line

Before diving into code, it helps to internalize how data flows through the system. Here's the shape of what I run.

  1. Every Gemini API call returns usageMetadata.totalTokenCount, which my server stores in a local database
  2. A background job runs every minute and reports any unsynced token usage to Stripe's Meter Event API
  3. At month end, Stripe issues an invoice combining the flat plan and the metered usage automatically
  4. Stripe webhooks (invoice.payment_succeeded, customer.subscription.updated, etc.) update the user's tier in my application database

The critical decision here is decoupling the Gemini API call from the Stripe report. Reporting in real time adds latency to every user request and bumps you into Stripe's API rate limits. Buffering in your own DB and flushing in batches is the realistic production pattern.

Thank you for reading this far.

Continue Reading

What follows includes implementation code, benchmarks, and practical content we hope you'll find useful. This site runs without ads — server and development costs are supported entirely by members like you. If it's been helpful, we'd be truly grateful for your support.

WHAT YOU'LL LEARN
You'll be able to ship a usage-based billing system that charges users for the Gemini API tokens they actually consume, with copy-paste-ready code
You'll learn how to sync Stripe subscription state via webhooks and gate AI features by tier in a way that survives real production traffic
You'll walk away with the idempotency, retry, and monitoring patterns indie AI SaaS founders need so the billing system doesn't quietly break
Secure payment via Stripe · Cancel anytime

Unlock This Article

Get full access to the rest of this article. Buy once, read anytime. This site is ad-free — your support goes directly toward keeping it running.

or
Unlock all articles with Membership →
Share

Thank You for Reading

Gemini Lab is ad-free, supported entirely by members like you. We publish practical guides daily with implementation code, benchmarks, and production-ready patterns. If you've found it useful, we'd love to have you on board.

  • Copy-paste ready implementation code
  • New advanced guides published daily
  • $5/mo or $10 for lifetime access
View Membership →

Related Articles

API / SDK2026-04-26
Architecting a Multi-Tenant SaaS on Gemini API — Tenant Isolation, Usage Metering, and Runaway Cost Defense in Production
A field-tested blueprint for serving Gemini API to multiple tenants on a single backend — covering tenant isolation choices, per-tenant rate limiting in Redis, request-level usage metering for billing, and runaway-cost defenses.
API / SDK2026-05-03
Building a Subscription SaaS on Gemini API and Cloudflare Workers — A Complete 2026 Implementation Guide
An end-to-end implementation guide for shipping a subscription SaaS on Gemini API, Stripe, and Cloudflare Workers — including model tier switching, KV-based access control, rate limiting, and the production edge cases that always show up.
API / SDK2026-06-28
When Gemini × Qdrant Hybrid Search Was Quietly Losing Recall — Field Notes on Instrumenting RRF Weights and Sparse-Vector Drift
Run Gemini embeddings with Qdrant hybrid search in production and your dashboards stay green while recall quietly slips. These field notes show how to catch it with measurement — RRF weights, sparse-vector drift, missing payload indexes — and protect it with a quality budget.
📚RECOMMENDED BOOKS
Build a Large Language Model (From Scratch)
Sebastian Raschka
LLM Dev
Prompt Engineering for LLMs
Berryman & Ziegler
Prompting
AI Engineering
Chip Huyen
AI Eng
* Contains affiliate links
See all →