โšก Software ยท LARZ-101 · Session 5 of 8

Building a Monetized API

Validate requests, auto-generate OpenAPI docs, paginate results, and send signed webhooks โ€” everything a paid JSON API needs.

⏱ 11 min read📅 Updated 2026-07-25📊 Code examples throughout

Validate input

import larz.api as api
api.enable(app)

@app.validate({"text": {"type": str, "required": True, "maxlen": 500}})
@app.post("/api/summarize")
def summ(req):
    return {"got": req.data["text"]}   # 400 with field errors if invalid

Automatic docs

One call generates a machine-readable spec at /openapi.json and a browsable page at /docs โ€” from your routes and schemas.

app.enable_docs(title="My API", version="1.0")

Pagination & webhooks

return api.paginate(Post.all(order="-id"), req, per_page=20)

from larz.api import Webhooks
wh = Webhooks(secret="whsec")
wh.deliver("https://customer.com/hook", "order.paid", {"id": 1})  # signed + retried

Takeaways

  • Validation, OpenAPI docs, pagination and webhooks are all built in.
  • Combine with API keys + metering (last session) to ship a complete paid API.
  • Full runnable example: examples/paid_api.py.

More in this course

Course home → · Browse all courses →