Larz › Monetize an AI API in Python

Build an AI product — and actually charge for it

Everyone's shipping AI apps; almost nobody has a clean way to bill for the tokens they burn. Larz makes AI monetization a framework primitive.

pip install larz
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)      # rate-limit + require credit
@app.post("/api/chat")
def chat(req):
    reply, usage = call_llm(req.data["prompt"])
    app.ai.charge(req, "gpt-4o", usage["in"], usage["out"])   # bill the tokens
    return {"reply": reply}

QuickstartGitHubAI course

Why it's different

No other Python framework gives you "build the AI product and charge for it" in one place. Full walk-through: Build & Monetize an AI App.

FAQ

How does token billing stay accurate below a cent?

app.ai.charge() accumulates cost in micro-dollars and debits whole cents from the customer's credit only as they accrue, so sub-cent calls aren't lost.

Can customers use their own API key?

Yes — BYOK keys are stored encrypted at rest; when a customer has one, Larz skips metering and they pay the provider directly.

Do I need any dependencies?

No. Token metering, BYOK encryption and billing are all built on the Python standard library.