jevrecipes

Recipe catalog / model-route

Route a request to a model tier

model-route is a Jev recipe from the jev-recipes TypeScript package. Which of the described models should serve request, and how much reasoning effort does it need, decided in one call so a cheap model handles easy turns and a capable one handles hard turns? Use it when an agent harness, gateway, or proxy chooses per request which LLM and thinking level to use, and you want that choice made in well under a second.

Last updated .

Explore this recipe interactively · Source and implementation guide · Markdown version

How do I use model-route in TypeScript?

Install with npm install jev-recipes. Requires Node.js 22.9 or newer and ES modules. Set TYPESAFE_API_KEY in your server environment for live calls, which send input to TypeSafe and use API quota. See the installation guide.

import { modelRoute } from 'jev-recipes/model-route';

const result = await modelRoute({
  "request": "Rename the variable `usr` to `user` in src/session.ts and fix any references.",
  "models": [
    {
      "id": "fast",
      "text": "Small, cheap, fast model. Good for edits with one obvious approach, reformatting, short answers, and simple lookups. Weak at multi-step reasoning and subtle bugs."
    },
    {
      "id": "balanced",
      "text": "Mid-size model at moderate cost. Handles multi-file changes, explanations, and routine debugging. Occasionally misses subtle design issues."
    },
    {
      "id": "frontier",
      "text": "Largest, slowest, most expensive model. Best for architecture, security-sensitive code, ambiguous requirements, and hard debugging."
    }
  ],
  "context": "Coding agent inside a small TypeScript repository with tests.",
  "minConfidence": 0.8
});
console.log(result);

What input does model-route take?

FieldTypeNeeded
requeststringRequired
modelsarrayRequired
contextstringOptional
minConfidencenumberOptional
Full input and result schemas
{
  "input": {
    "$schema": "https://json-schema.org/draft/2020-12/schema",
    "type": "object",
    "properties": {
      "request": {
        "type": "string"
      },
      "models": {
        "minItems": 1,
        "maxItems": 50,
        "type": "array",
        "items": {
          "type": "object",
          "properties": {
            "id": {
              "type": "string"
            },
            "text": {
              "type": "string"
            }
          },
          "required": [
            "id",
            "text"
          ]
        }
      },
      "context": {
        "type": "string"
      },
      "minConfidence": {
        "type": "number",
        "minimum": 0,
        "maximum": 1
      }
    },
    "required": [
      "request",
      "models"
    ]
  },
  "result": {
    "$schema": "https://json-schema.org/draft/2020-12/schema",
    "type": "object",
    "properties": {
      "model": {
        "type": "string"
      },
      "usage": {
        "type": "object",
        "properties": {
          "input_tokens": {
            "type": "integer",
            "minimum": 0,
            "maximum": 9007199254740991
          },
          "output_tokens": {
            "type": "integer",
            "minimum": 0,
            "maximum": 9007199254740991
          }
        },
        "required": [
          "input_tokens",
          "output_tokens"
        ],
        "additionalProperties": false
      },
      "status": {
        "type": "string",
        "enum": [
          "ready",
          "review"
        ]
      },
      "verdict": {
        "type": "string",
        "enum": [
          "matched",
          "none",
          "ambiguous"
        ]
      },
      "selection": {
        "type": [
          "string",
          "null"
        ]
      },
      "suggestedSelection": {
        "type": [
          "string",
          "null"
        ]
      },
      "confidence": {
        "type": "number",
        "minimum": 0,
        "maximum": 1
      },
      "probabilities": {
        "type": "object",
        "properties": {
          "candidates": {
            "type": "object",
            "propertyNames": {
              "type": "string"
            },
            "additionalProperties": {
              "type": "number",
              "minimum": 0,
              "maximum": 1
            }
          },
          "none": {
            "type": "number",
            "minimum": 0,
            "maximum": 1
          },
          "ambiguous": {
            "type": "number",
            "minimum": 0,
            "maximum": 1
          }
        },
        "required": [
          "candidates",
          "none",
          "ambiguous"
        ],
        "additionalProperties": false
      },
      "effort": {
        "type": "string",
        "enum": [
          "low",
          "medium",
          "high"
        ]
      },
      "effortLevel": {
        "type": "integer",
        "minimum": 0,
        "maximum": 2
      },
      "effortScore": {
        "type": "number",
        "minimum": 0,
        "maximum": 2
      },
      "effortConfidence": {
        "type": "number",
        "minimum": 0,
        "maximum": 1
      },
      "effortProbabilities": {
        "type": "object",
        "propertyNames": {
          "type": "string"
        },
        "additionalProperties": {
          "type": "number",
          "minimum": 0,
          "maximum": 1
        }
      }
    },
    "required": [
      "model",
      "usage",
      "status",
      "verdict",
      "selection",
      "suggestedSelection",
      "confidence",
      "probabilities",
      "effort",
      "effortLevel",
      "effortScore",
      "effortConfidence",
      "effortProbabilities"
    ],
    "additionalProperties": false
  }
}

What does a model-route result look like?

This hand-authored response demonstrates the contract. It is not a model accuracy measurement. Run it without an API key: npx jev-recipes demo model-route.

{
  "model": "demo-fixture",
  "usage": {
    "input_tokens": 0,
    "output_tokens": 0
  },
  "status": "ready",
  "verdict": "matched",
  "selection": "fast",
  "suggestedSelection": "fast",
  "confidence": 0.92,
  "probabilities": {
    "candidates": {
      "fast": 0.92,
      "balanced": 0.05,
      "frontier": 0.01
    },
    "none": 0.01,
    "ambiguous": 0.01
  },
  "effort": "low",
  "effortLevel": 0,
  "effortScore": 0.1,
  "effortConfidence": 0.9,
  "effortProbabilities": {
    "0": 0.9,
    "1": 0.1,
    "2": 0
  }
}

Input

See shared options and behavior for client configuration, validation, and errors. Types are inferred from this folder's Zod 4 schemas.

models lists up to 50 candidates with unique ids. Each text should say what the model is good at, what it is weak at, and its relative cost, because the recipe prefers the cheapest model whose description covers the request. context can carry the environment, the conversation so far, or constraints such as latency budgets.

Result

selection is the chosen model id when the result is ready, otherwise null. suggestedSelection keeps a low-confidence pick for logging. verdict is matched, none, or ambiguous; none means no described model fits, which usually signals a gap in the descriptions. probabilities.candidates is keyed by your model ids.

effort is low, medium, or high, taken from the most likely rubric level, with effortLevel as its index and effortScore as Jev's expected value between 0 and 2. effortConfidence and effortProbabilities describe that second judgment. Map effort onto your provider's thinking or reasoning parameter.

A result is ready when the selection confidence meets minConfidence and the verdict is not ambiguous. The effort grade does not affect status; read effortConfidence if you want to gate on it.

Reuse and calls

Uses the shared selection question and score parser. One live invocation makes one Jev request carrying both questions. This folder owns the routing instruction, the effort rubric, and the mapping onto model ids.

Limits

Describe models by capability and cost, not by name alone. A description such as "the best model" gives the recipe nothing to compare.

The effort grade reads the request text. A short request can still be hard; supply context when the difficulty lives in the surrounding state.

Example input

demo.json contains editable input and a hand-authored response. After installing jev-recipes, npx jev-recipes demo model-route shows an offline illustration, not an accuracy measurement. Use npx jev-recipes describe model-route to inspect the input and result schemas.

How accurate is model-route?

Current mixed-source measurement

jev-1.13.0 / 2026-10-04 / 104 development cases

Scoring revision 2.

89%All-case accuracy
40Sent for review
0Failed calls / cases

64 ready decisions, with 98% accuracy among those decisions.

95% case-level interval: 81% to 93%. Related synthetic cases are correlated.

This measures the recorded dataset, not general readiness. Label sources: unspecified: Existing repository labels; independent review and original authorship were not recorded.; author-synthetic: AI-authored synthetic boundary cases for jev-recipes; labels have not had independent human review.

Use the evaluation guide to measure this decision on your own labeled cases.

What are the limits of model-route?