Larz OS โ€บ Larz โ€บ Paid API tutorial

Build a paid API in Python

Charge per API call from prepaid credit โ€” the whole billing layer is one decorator.

Selling an API by the call is the classic indie-hacker product, and it's exactly what Larz's @app.metered primitive is for. No Stripe SDK, no webhook plumbing.

1. Enable money

from larz import Larz, Response
import larz.money as money
app = Larz(secret="...")
money.enable(app)                       # dev: keyless MockProvider

2. Meter an endpoint

@app.metered("$0.01/call")
@app.post("/api/enrich")
def enrich(req):
    data = req.json()
    return Response.json({"result": do_work(data), "charged_cents": 1})

A caller with no balance gets a clean 402 Payment Required pointing at the top-up page. A funded caller is debited a cent and served.

3. Sell credit packs

app.money.credit_pack("starter", price="$5", credit="$5")
app.money.credit_pack("bulk", price="$20", credit="$25")   # +25% bonus

Larz auto-serves /larz/pricing, /larz/credits, and a /larz/admin revenue dashboard. Ship the same pattern for a subscription with @app.paid("$9/mo", trial_days=7).

Go deeper in the docs, or compare approaches in Larz vs Flask vs Django. Want to accept crypto? LarzCoin plugs in as a payment provider.