Spring AI TypeSafe and Jev: build a model router

Build a Spring Boot model router with TypeSafe 0.1.0 and Jev, then return the chosen OpenAI model, confidence, probabilities and answer from one endpoint.

Player not loading? Watch on YouTube

Dan Vega builds a Java model router that uses Jev to choose an OpenAI model before Spring AI sends the prompt. The routing instruction favors the cheapest configured tier unless the request needs more capability. The example exposes the selected tier and confidence alongside the answer so the routing decision can be inspected.

The walkthrough starts at start.spring.io with Spring Boot 4.1.1, JDK 27, Spring Web and the OpenAI provider. Vega adds the Spring AI TypeSafe starter at version 0.1.0 and configures separate OpenAI and TypeSafe API keys through environment variables. He describes TypeSafe as a new Spring AI community project outside the main official repository.

A ModelTier enum defines Luna, Terra, Sol and Astra with model IDs and capability descriptions. The ModelRouter turns those tiers into options for a Choice question. A RoutingDecision record carries the selected tier, model ID, confidence and probabilities. The controller uses OpenAiChatOptions to override the default model for each request and returns the routing details alongside the answer.

In the reported demos, "hello there" selects GPT 5.6 Luna, while a multi-region PostgreSQL failover prompt selects GPT 5.6 Sol. Vega says Jev's decision step is fast, but the example also waits for the model's response. The demonstrated setup calls external services; Ollama and Docker Model Runner receive brief mentions as alternatives for a local LLM provider.