◉CLAUDE LABJP
●SONNET 4.5 — Sonnet 4.5 was retired from the Claude API on 11/30. Calls now return an error. Move to Sonnet 5.5●PROJECTS — The Enterprise Analytics API now reports daily usage for the new projects experience (beta)●OPUS 4.5 — claude-opus-4-5 retires on 2027/1/22, 52 days from now. The replacement is claude-opus-5-5●LANGUAGE — Some users say Claude switches to another language mid-session while they write in English●NEW — New: Weekly usage looks like it jumped right after a plan upgrade? Check this first●COWORK — Handing Cowork a folder for the first time? Start with a task that only reads files●SONNET 4.5 — Sonnet 4.5 was retired from the Claude API on 11/30. Calls now return an error. Move to Sonnet 5.5●PROJECTS — The Enterprise Analytics API now reports daily usage for the new projects experience (beta)●OPUS 4.5 — claude-opus-4-5 retires on 2027/1/22, 52 days from now. The replacement is claude-opus-5-5●LANGUAGE — Some users say Claude switches to another language mid-session while they write in English●NEW — New: Weekly usage looks like it jumped right after a plan upgrade? Check this first●COWORK — Handing Cowork a folder for the first time? Start with a task that only reads files
Articles/Claude Code
⟐ Claude Code/2026-05-03Advanced

Claude × Stripe Meter Events — Building a Usage-Based SaaS

Billing Claude API tokens through Stripe Meter Events: counting cache tokens correctly, the 24-hour identifier dedup window, why caps belong in a Durable Object rather than KV, cancellations, and daily reconciliation — checked against official docs as of November 2026.

Claude57Stripe16Meter EventsUsage-Based BillingSaaS15Cloudflare Workers17

✦ Premium Article

The night I finished replaying a month of test traffic, I put two numbers side by side: the total on my Stripe meter, and the total in my own token log. They didn't match. The gap was around ten percent, and Stripe was always the lower one. It took me an uncomfortable evening to find it — my code had never counted a single token that came back from the prompt cache.

If you're about to put usage-based pricing on top of the Claude API, I suspect this is the kind of drift that will hurt you most. Overcharge and you lose trust; undercharge and your costs quietly pile up. What follows rebuilds the whole path as one flow: counting the tokens you should actually bill from Claude's usage, delivering them to Stripe Meter Events without double counts or gaps, enforcing caps, and undoing mistakes.

The stack is Cloudflare Workers + Durable Objects + Stripe, but the reasoning carries over to other platforms. Every price, limit, and API behavior below is what the official docs said when I checked them in November 2026.

Separate counting, stopping, and billing

Most usage-billing trouble comes from asking one component to do three jobs. A Stripe meter aggregates for invoicing — it will never stop a runaway customer. A home-grown cap counter, on the other hand, won't produce an invoice.

My ledger counts, my app stops, Stripe bills. I build these as three separate parts and reconcile them once a day. The steps below follow that order.

JobWhere it livesWhat it must guarantee
Count (ledger)Your own DB (D1 or similar)One row per request, the identifier, and its send status
Stop (caps)A Durable Object per customerUpdates for one customer happen in order and are readable immediately
BillStripe Meter + PriceAggregation, invoice generation, and the finalization grace period

Your options as of November 2026

Stripe used to offer Usage Records for metered billing. Since API version 2025-03-31.basil, legacy metered prices — usage_type=metered without a meter — can no longer be created or attached to subscriptions. If you're starting today, meters are the default path.

Within meters, there are still three ways to report usage:

ApproachThroughput (per Stripe docs)Good fitWatch out for
Own counter, compute the bill at month endWhatever your DB handlesComplex tiering, or a human review before invoicingYou write invoicing, proration, and corrections yourself
Meter Events (API v1)1,000 calls/sec per account in live mode, plus one concurrent call per customer per meterMost SaaS products from launch to mid-scaleParallel sends for the same customer collide
Meter event streams (API v2)Up to 10,000 events/sec, live mode onlyHigh-volume servicesSession tokens expire after 15 minutes and must be recreated

The decision fits in one line: if a single customer can send you several requests per second, use v2; otherwise send v1 events in series. The code in this article uses v1 and serializes per customer through a Durable Object. I haven't run the v2 SDK calls end to end myself, so I'm leaving that code out rather than guessing.

✦

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 count billable input as the three-field usage sum with cost weights, so your ledger and Stripe drift to 0
✦You'll stop cross-day double counts by treating your ledger's sent status as truth, since identifier dedup lasts about 24 hours
✦You'll enforce per-customer caps in a Durable Object instead of KV, which allows only 1 write per second per key
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

Claude 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

⟐ Claude Code2026-10-28
Back From Checkout, the Button Stayed on Processing: Why I Fixed It With pageshow, and the 3 Files My Audit Still Found
When you press Back from Stripe or another external page, a checkout button can stay stuck on Processing. I reproduce the bfcache cause in a real browser, compare pageshow with no-store, and add a repo audit script and a CLAUDE.md rule.
⟐ Claude Code2026-10-22
I Recounted the Bytes: Why Keeping Article Bodies Out of My Worker Bundle Still Holds Up at About 900 Articles
On my own Next.js site running on Cloudflare Workers, I recounted the bytes of a bundle that carries article bodies versus one with metadata only. Here are the headroom, a breakdown I had not expected, and a script that keeps counting.
⟐ Claude Code2026-08-19
Fixing the Code Doesn't Evict a Broken Page From the Edge Cache
I shipped a fix and the broken page kept serving. The problem was not the code but the edge cache, which had stored a broken HTML response because the store decision looked only at the status code. Here is the integrity guard I now run before every cache write, and the thresholds I had to tune in production.