Larz › Blog › Larz 1.2: The Revenue Engine โ€” pricing-as-code, analytics, and AI monetization

Larz 1.2: The Revenue Engine โ€” pricing-as-code, analytics, and AI monetization

July 27, 2026 · Larz OS

Not just take a payment โ€” run the whole money lifecycle: pricing, metering, analytics, recovery, referrals, and AI token billing, all as framework primitives.

Every framework helps you serve a request. Larz helps you get paid for it โ€” and 1.2 goes all the way: it makes revenue itself a first-class concept, and it's built for the thing everyone is shipping now, AI products you can actually charge for.

pip install --upgrade larz     # 1.2.0

Pricing-as-code

Your entire pricing is one object. It generates the pricing page, checkout, entitlements and metered prices โ€” one source of truth.

from larz.pricing import Pricing
(Pricing()
 .plan("free", "$0",     limits={"projects": 3})
 .plan("pro",  "$19/mo", trial_days=14, highlight=True,
       features=["API access"], limits={"projects": None, "api": True})
 .usage("api_call", "$0.002/call")
 .coupon("LAUNCH50", percent_off=50)
 .mount(app))

Then gate anything on the plan: if app.feature(req, "api"), app.within_limit(req, "projects", count).

Revenue analytics, built in

MRR, ARR, ARPU, LTV, churn and a 30-day chart at /larz/admin/revenue โ€” computed from your own payment data. A self-hosted mini-Baremetrics.

import larz.analytics as analytics
analytics.enable(app, token="secret")
m = app.money.metrics()      # {"mrr_cents": ..., "arr_cents": ..., "churn_rate": ...}

Dunning & recovery

Failed renewals are revenue most indie apps just lose. Larz retries them on a schedule and recovers what it can before revoking access.

@app.schedule("0 9 * * *")
def dun(): app.money.run_dunning(on_notify=send_reminder_email)

Referrals & affiliates

import larz.referrals as referrals
referrals.enable(app, reward="20%")
url = app.referrals.url(req.subject)      # when a referred user pays, 20% is credited

AI monetization (the co-headline)

Bill the tokens your AI endpoints burn โ€” with sub-cent accuracy, per-plan rate limits, and BYOK (customers bring their own key, encrypted at rest, and skip metering).

import larz.ai as ai
ai.enable(app)
app.ai.price("gpt-4o", input="$2.50/1M", output="$10/1M")

@app.ai_metered("gpt-4o", per_minute=20)
@app.post("/api/chat")
def chat(req):
    reply, usage = call_llm(req.data["prompt"])
    app.ai.charge(req, "gpt-4o", usage["in"], usage["out"])   # tokens billed
    return {"reply": reply}

This is the sharp part: nobody else gives you "build an AI product and charge for it" in one framework. The whole thing runs on the standard library โ€” the BYOK encryption (larz.crypto) is HMAC-SHA256 authenticated encryption, no dependency.

See the changelog, the AI SaaS example, and the new Build & Monetize an AI App course.

Read the docs PyPI

FAQ

Is Larz 1.2 still zero-dependency?

Yes โ€” pricing, analytics, dunning, referrals, AI metering and the BYOK encryption are all built on the Python standard library.

What does 'revenue-native' mean?

Beyond taking a payment, Larz treats the whole money lifecycle as primitives: pricing, plans, metering, analytics (MRR/churn/LTV), failed-payment recovery, referrals and payouts.

How does AI token billing stay accurate below a cent?

app.ai.charge() accumulates cost in micro-dollars and only debits whole cents from the customer's credit as they accrue, so tiny per-call costs aren't lost to rounding.

release1.2