All skills

Usage credits

usage-credits
PaidPaymentsVersion 1.0.0

Prepaid credit packs on Creem: each request spends credits once, failed work is refunded, and an empty balance answers 402 with a buy prompt.

Full description

Adds prepaid usage credits to an app on Creem's Customer Credits API. Credit-pack products grant credits on payment and claw them back on refund; the app links buyers from the webhook or the success page, charges each request once with an idempotency key, gives credits back when work fails, and answers 402 with a buy prompt when the balance is short. Ships a zero-dependency core, Next.js App Router routes, a local SQLite ledger with the same interface (Paddle or manual grants), 17 offline tests, a live test-mode smoke test, and a headless test-card helper. Use when the user wants credits, tokens, a pay-as-you-go or top-up model, AI generation limits, "out of credits" handling, or to bill per request on Creem.

A sample Next.js app on Creem test mode: 3 free credits spent, a 402 with nothing charged, a real test-card purchase, then 100 credits back in the app. · Recorded 2026-11-03

  1. 1Each caption debits 1 credit through Creem's API; the 4th request gets 402 and runs nothing
  2. 2Buy 100 credits opens a Creem test checkout, paid with the test card (sped up 2.5x)
  3. 3The success page confirms the checkout with Creem and links the account: balance 100, next caption 99
  4. 4Terminal: 17 offline tests, then the smoke test against test-api.creem.io

Previews

What it does

Prepaid credit packs on Creem: each request spends credits once, failed work is refunded, and an empty balance answers 402 with a buy prompt.

  • Uses Creem's Customer Credits: a pack product grants credits on payment and takes them back on refund, so your app keeps no balance of its own
  • spendCredits() debits before the work and reverses the debit if the work fails; a retried request with the same id is charged once
  • Next.js routes for buying a pack, the success page (checks the checkout with Creem, not the URL), balance, a paid action returning 402, and the webhook
  • Behaviour checked against the Creem test API on 2026-11-03, including the cases the docs leave open: refunds can leave a negative balance, and the API refuses to reverse spent credits
  • Same interface on your own SQLite ledger (Paddle or anything else): expiring credits, refund debt, parallel overspend blocked; 17 offline tests and a live smoke test
Try it with this prompt
Use the usage-credits skill to add prepaid credits to my app: a 100-credit pack on Creem, 1 credit per generation, and a buy-credits prompt when the balance runs out.

Full instructions are included with purchase

This is a paid skill. Buy it on its own or get every skill with a plan. Buyers download it from this page or their account.

Outline

  1. 01When to use / when not to
  2. 02What you get
  3. 03Steps
  4. 04Rules
  5. 05Done when
  6. 06Troubleshooting

What's inside

25 files: SKILL.md, 5 scripts, 8 references, 10 templates and assets, 1 tests.

usage-credits/
  • SKILL.md7.7 KB
  • assets/(10)44.3 KB
    • lib/(1)27.7 KB
      • credits-core.mjs27.7 KB
    • nextjs/(9)16.5 KB
      • src/(8)15.9 KB
        • app/(5)6.7 KB
          • api/(4)5.1 KB
            • credits/(2)1.8 KB
              • balance/(1)503 B
                • route.ts503 B
              • checkout/(1)1.3 KB
                • route.ts1.3 KB
            • generate/(1)1.6 KB
              • route.ts1.6 KB
            • webhooks/(1)1.7 KB
              • creem/(1)1.7 KB
                • route.ts1.7 KB
          • credits/(1)1.6 KB
            • success/(1)1.6 KB
              • page.tsx1.6 KB
        • lib/(3)9.2 KB
          • credits-core.d.mts4.7 KB
          • credits.ts4.0 KB
          • current-user.ts600 B
      • .env.example620 B
  • references/(8)15.7 KB
    • fixtures/(5)7.4 KB
      • checkout.completed.json3.0 KB
      • credits.consumed.json486 B
      • credits.granted.json478 B
      • customer_credits.exhausted.json419 B
      • refund.created.json3.0 KB
    • creem-credits.md4.8 KB
    • ledger-design.md1.5 KB
    • pricing-credits.md1.9 KB
  • scripts/(6)35.0 KB
    • template-check/(1)5.7 KB
      • routes.test.ts5.7 KB
    • check_nextjs_template.sh2.0 KB
    • create_credit_pack.mjs2.9 KB
    • credits_smoke.mjs4.7 KB
    • pay_test_checkout.mjs4.2 KB
    • selftest.mjs15.6 KB

Questions

What does Usage credits do?

Prepaid credit packs on Creem: each request spends credits once, failed work is refunded, and an empty balance answers 402 with a buy prompt.

Which agents does it work with?

Claude Code, Codex, Cursor and any other agent that reads the Agent Skills format (a folder with SKILL.md). Paste the install prompt into your agent, or unzip the folder into its skills directory.

What is in the download?

25 files: SKILL.md, 5 scripts, 8 references, 10 templates and assets, 1 tests.

How much is it?

$6.99 one-time on its own, with 12 months of updates. It is also part of the Get Paid Pack. Yearly and lifetime plans include every paid skill.

Can I get a refund?

A first payment can be refunded in full within 14 days if no paid skill was downloaded. After a download, no refund unless a skill is defective and we can't fix it.

How do updates work?

One-time purchases get 12 months of updates; yearly and lifetime get updates while active. Download again from this page or your account. Current version: 1.0.0.