← Lesson
Routing Models
Joeven
Run
Reset
Python loads on first run
def route(task): if task["kind"] in {"classify", "extract", "route_tools"}: return "small" if task.get("schema") == "json" and task["kind"] == "tool_call": return "small" if task["kind"] in {"plan", "debug"}: return "large" return "large" def bill(model, tokens): rates = {"small": 0.2, "large": 3.0} return tokens * rates[model] / 1000000 tasks = [ {"kind": "classify", "tokens": 800}, {"kind": "tool_call", "schema": "json", "tokens": 1200}, {"kind": "debug", "tokens": 4000}, {"kind": "plan", "tokens": 3000}, ] all_large = sum(bill("large", t["tokens"]) for t in tasks) routed = sum(bill(route(t), t["tokens"]) for t in tasks) print("always large usd", round(all_large, 6)) print("routed usd", round(routed, 6)) print("decisions", [(t["kind"], route(t)) for t in tasks])
Run to execute this in your browser. Nothing is sent to a server.