Loading component…
Loading component…
How a gateway splits its traffic across AI models – streaks of light into each model's line, as wide as its share; pick Cost, Balanced or Quality and the split and price change
To reuse this local React demo, copy all files from the Code tab into the same folder, then import ModelRouter from ./model-router.
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)}
/>
);
}| 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 |
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"