Intermediate35 min

Project: Model Router

Send easy requests to a cheap model and hard ones to an expensive one. Measure what you saved.

Most requests hitting your LLM endpoint are easy. Someone wants a string reformatted, a short question answered, a sentence rewritten. A small model handles those indistinguishably from a frontier model, at a fraction of the price. The problem is that you cannot tell which request is which until after you have answered it.

Unless you ask first. This is intent routing pointed at your own cost structure: a Choice over what the request is, a Score over how hard it is, and a dispatch table that picks the model.

from typesafe_sdk import Choice, Score, TypeSafeClient

client = TypeSafeClient(model="jev-1.13")

ROUTER = {
    "task": Choice(
        instructions="What kind of work does this request ask for",
        criteria={
            "lookup": "Retrieve or restate a specific fact from the provided context",
            "transform": "Reformat, translate, summarize, or rewrite supplied text",
            "generate": "Produce substantial new content such as an essay or a draft",
            "reason": "Work through a problem with multiple dependent steps",
            "code": "Write, review, or debug source code",
        },
    ),
    "complexity": Score(
        instructions="How much capability does answering this well require",
        criteria=[
            "Trivial: a small model handles this perfectly",
            "Moderate: some nuance, but well within a small model",
            "Hard: needs careful handling or domain knowledge",
            "Very hard: multi-step reasoning or high cost of being wrong",
        ],
    ),
}

Full lesson

Keep reading Project: Model Router

The rest of this lesson — including the interactive exercises and the worked project — is part of Patterns in Production.

  • Every lesson in all three courses
  • Interactive builders, graders, and playgrounds
  • 1,000 live Jev credits, for the courses and the playground
  • Project source you can run yourself
  • Free updates as Jev ships new versions
Browse free lessons

Already bought them? Sign in to unlock — no need to buy twice.