Claude Templates / S-tier · Foundation

Foundation

The Credit Metering Playbook

A credit ledger, atomic spend RPC, refund-on-failure, and cost analytics that hold up.

CREDIT-METERING-PLAYBOOK.md · 13 sections · 2,547 words · 20 KB · markdown

If your app charges per output — a render, a generation, an enrichment — this is the metering layer. An append-only ledger, an atomic spend RPC that can't double-charge under concurrency, automatic refunds when a provider call fails, and the admin views that tell you whether your pricing is actually profitable.

What's inside

When to use it

Week 3, only if the app charges per-output.

Straight from the file

Seed credit_pricing with on conflict (format_key) do update set that refreshes metadata only — never blow away admin cost overrides:

Table of contents

  1. 0. Use this spec
  2. 1. Architecture
  3. 2. Schema
  4. 3. Pricing table seed
  5. 4. Atomic spend RPC
  6. 5. Server spend helper + pre-spend validation
  7. 6. Refund-on-failure (worker pattern)
  8. 7. Beta auto-refill + founding tier
  9. 8. Daily quota gate (optional)
  10. 9. Cost analytics views
  11. 10. Audit-orphan-charges cron (safety net)
  12. 11. Common pitfalls
  13. 12. Kickoff prompt

How to run it

Drop CREDIT-METERING-PLAYBOOK.md into your repo, then tell Claude Code: “Read CREDIT-METERING-PLAYBOOK.md and implement it in this codebase.” It's written for an agent to execute end to end. Search the file for angle-bracket placeholders and swap in your own project names, domains, and keys before the first run.

↓ Download the playbook

More foundation playbooks

← All 28 Claude templates