๐Ÿค– Software ยท LARZ-501 · Session 2 of 8

Your First AI Endpoint

Build a JSON endpoint that calls a language model and returns a result.

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

An endpoint that calls an LLM

from larz import Larz
app = Larz(secret="...")

@app.post("/api/write")
def write(req):
    prompt = req.json()["prompt"]
    reply, usage = call_llm(prompt)      # your provider call
    return {"reply": reply}

Return a dict and Larz serializes JSON automatically. usage here is the token count your provider reports (prompt + completion) โ€” you'll bill on it next.

Takeaways

  • Any provider works โ€” you make the call, Larz handles the web layer.
  • Capture the token usage the provider returns; it's what you meter.

More in this course

Course home → · Browse all courses →