affectUI › Components › Agents
Model Router
How a gateway splits its traffic across AI models – requests run as streaks of light from the gateway into each model's line, the line as wide as its share. The blended cost per 1K tokens on top and how it compares to what's live; pick Cost, Balanced or Quality and the split changes, the lines widen and narrow and the numbers roll. Every route below with share, p95 latency and price, a fallback to retry on another model, and Deploy.
Part of affectUI Pro. Install: npx shadcn@latest add https://www.affectui.com/r/model-router.json · Import from @/components/ui/model-router
When to use
- Showing how an AI gateway splits its traffic across models – and letting people pick a strategy for it
- Comparing what a cheaper or a stronger split would cost against the policy that's live, before deploying it
- Setting a fallback model that takes over when another one fails
When not to use
- How much each model was used over a period – use Model Usage
- Picking one model for a chat – use Model Picker
- Requests routed to agents rather than models – use Agent Router
Usage
import { ModelRouter, type RouterModel, type RouterStrategy } from "@/components/ui/model-router";
const models: RouterModel[] = [
{ id: "opus", name: "Claude Opus 5.5", provider: "Anthropic", logo: <ClaudeLogo />, p95: 2.16, cost: 0.0126 },
{ id: "gpt", name: "GPT-5.5", provider: "OpenAI", logo: <OpenAILogo />, p95: 1.34, cost: 0.0048 },
{ id: "flash", name: "Gemini 3 Flash", provider: "Google", logo: <GeminiLogo />, p95: 0.64, cost: 0.0007 },
];
const strategies: RouterStrategy[] = [
{ id: "cost", label: "Cost", shares: { opus: 6, gpt: 30, flash: 64 } },
{ id: "balanced", label: "Balanced", shares: { opus: 20, gpt: 50, flash: 30 } },
{ id: "quality", label: "Quality", shares: { opus: 60, gpt: 32, flash: 8 } },
];
export function Router() {
return (
<ModelRouter
models={models}
strategies={strategies}
live={{ strategy: "balanced", fallback: { enabled: true, from: "opus", to: "gpt" } }}
version={14}
environment="chat-prod"
onDeploy={(policy) => savePolicy(policy)}
/>
);
}Props
| Name | Type | Default | Description |
|---|---|---|---|
models | RouterModel[] | The models the gateway routes to, top to bottom – each a line in the flow and a row in the table | |
RouterModel | { id, name, provider?, logo?, color?, p95, cost } | p95 is the latency in seconds, cost the price per 1K tokens in dollars; provider shows on hover | |
strategies | { id, label, shares }[] | The switch on top – shares are each model's part of the traffic by id, scaled to add up to 100% | |
live | { strategy, fallback: { enabled, from, to } } | The policy that's live now – where it starts, and what the blended cost is compared to | |
version | number | The live policy's version – "Policy v14"; it goes up by one with every deploy | |
environment | string | Where it runs – "chat-prod", shown in the header and the footer | |
onDeploy | (policy) => void | Promise<void> | Deploys the policy – while a returned promise runs the button says Deploying | |
onChange | (policy) => void | Every edit to the strategy or the fallback | |
title | string | The heading and the section's accessible name | |
className | string | Extra class on the root – set the color variables on it |
Accessibility
- The strategy switch is a radio group with one tab stop – arrows move between Cost, Balanced and Quality
- The fallback is a switch with its state; each model picker opens a menu with Enter, Space or the arrows – arrows, Home and End move, Enter picks, Esc closes and puts focus back, Tab leaves it
- Revert moves focus to Deploy, so it never gets lost when the button goes away
- The routes are a real table with column and row headers
- The footer says Live, Unsaved changes or Deploying in words and is announced as it changes; Deploy is aria-disabled until something changed
- The flow is decoration and hidden from screen readers – the table carries the numbers
- A focus ring shows only for the keyboard
Responsive
- Fills its container's width – the lines stretch, the model names stay on the right
- Below 440px the strategy switch moves under the cost and the table keeps share and price
- Below 380px the fallback's pickers show just the model's logo – the name is in their label and their menu – so the rule stays on one line
- Long model names, strategy labels and the environment end in … with the full text on hover; long strategy lists wrap
- One model hides the fallback; no models at all reads No models to route to
- A fallback naming a model that isn't in the list falls back to the first ones, never the same model twice
- A strategy without shares splits evenly; shares that don't add up to 100 are scaled
- The classic style has a rounder card with a hairline border, pill switch, tags and buttons and firmer type – the same behavior as the clean one
- Dark mode built in: switches when an ancestor (usually <html>) has the class dark or data-theme="dark"
Requirements
- React 19
Related
- Model Usage – How much each AI company's models were used – one stacked bar per company in its color with a segment per model, the most used darkest and the rest lighter shades; point at a bar for its models and their share. The period's total and change on top with tokens, cost and requests to switch between, and below what it all went into – search, analyze, code, test – across every model, or just the company you point at
- Agent Router – A router agent sorting incoming requests to the agents that handle them – the request coming in on top, the router under it and the agents side by side at the bottom, each with its task queue below, all as Agent Crew's cards on its soft blue connectors – people sit off to the right, a fading line with a Human tag. A light runs into the router, which reads the request and settles on an agent with a confidence; the light runs on, the agent's card lights up in its color and the request drops into its queue. Unsure, it hands the request to a person. A click opens why it went where it went, with every agent's score and a way to send it elsewhere
- Model Picker – The model menu of an AI chat – point at a model and its speed, quality and cost bars fill, switch on extended thinking and its effort unfolds, while the tray rolls the first-token time and price
- Cost Waterfall – Where the money and tokens of an agent run go – every LLM call, tool call and sub-agent as a step in a waterfall, with model, tokens, cost and time, the most expensive step on top and a switch between cost and tokens