API keys & roles
Ship a paid API: keys are the principal, billing follows the key.
API keys
key = app.auth.issue_api_key(user=None, plan="pro", label="acme")
class=com># 'key' is shown once; only a hash is stored.
@app.api_key_required(plan="pro") class=com># 401 no key, 403 wrong plan
@app.metered("$0.01/call")
@app.post("/api/x")
class=kw>def x(req):
class=kw>return {"key_plan": req.api_key.plan}
Metering a keyed request bills apikey:<id> (or the key's user, if it has
one) โ never the anonymous session.
Roles (RBAC)
@app.require_role("admin") class=com># 401 anon, 403 wrong role
@app.get("/admin-only")
class=kw>def secret(req): ...
Combine with request validation and OpenAPI docs
to ship a complete, documented, monetized API.