SimpleA plain explanation, one diagram and an analogy, with where the analogy breaks.
Guess first: what does the router do when one provider is down? Show the answerIt picks another company that is working, like a taxi app sending a car from a different firm.
Most people never run an AI themselves. Their app sends a message over the internet to a company that runs it, and pays a tiny amount for each word.
A router is like a taxi app. You ask for a ride, and it picks which company sends the car.
A model API is a web endpoint: you send the conversation as JSON and get the reply back, often streamed token by token. You pay per token, usually quoted per million, and input and output tokens are often priced differently.
Many providers and local servers copy the same request format, often called OpenAI-compatible. Switching can be as small as changing the base URL and the model name.
A router or aggregator sits in front of many providers. One key and one bill reach many models, and it can send each request to whichever provider is cheaper, faster or currently up.
One request through a router
Like: A taxi app that picks which company sends the car. Where it breaks: Any taxi gets you to the same place. Two providers serving the "same" model can differ in quantization, context limit and supported features, so the answer you get may depend on which one the router picked.
How it worksAn interactive demo first, then the mechanism: light maths, pseudo-code and trade-offs.
A request's bill is tokens × price, summed over its parts. Input and output are priced separately per million tokens, and output usually costs several times more per token than input.
Prompt caching stores a repeated prefix, such as instructions, tool definitions or a long document. A request that finds it cached pays a fraction of the input price for those tokens; one that misses pays a premium to write it. Only an exact prefix matches, so anything that changes must go at the end.
A batch interface trades speed for price: you submit many requests at once and collect the results within hours, at a discount. Agents multiply everything, because one task means many calls, each resending its context.
Caching pays only when the prefix is long, identical and reused before it expires. A cache write costs more than sending the same tokens uncached.
Below a minimum length, from a few hundred to a few thousand tokens depending on the model, a prefix is not cached at all.
A batch discount comes with a wait of up to a day, so it suits evaluations and bulk jobs, not chat.
Output is the expensive side. Capping or shortening replies often saves more than squeezing the input.
The agent and multi-agent multipliers are averages from one company's data. Measure your own, because the ratio depends on the task and the design.
A per-token price is only part of the bill: retries, failed runs and growing contexts add tokens nobody planned for.
ResearchWhere the simple picture breaks, open problems and primary sources.
One request format makes providers look interchangeable. In practice the same call can behave differently by provider, by date and even by server load.
Compatibility is a convention. Tool calling, caching, reasoning settings and errors differ between "compatible" servers, so a switch of provider needs its own tests (one compatible server).
Same name, different model. A hosted model can change behind a fixed name: one study saw accuracy on a maths task fall from 84% to 51% between two releases three months apart (Chen et al., 2023). Pin versions and rerun evals.
Not deterministic at temperature 0. Server kernels change their order of arithmetic with batch size, which depends on other users' traffic, so identical requests can get different answers (Thinking Machines, 2025).
Hidden tokens. Internal reasoning is billed as output tokens even when the app shows little of it, so the visible answer understates the cost (one provider’s docs).
Security on this concept: 3 threats Pending expert review
Encrypted chat traffic still reveals the topic Pending expert review
Exposed
Streamed responses, sent token by token over encrypted connections
The sizes and timing of those packets, visible to anyone on the network path
Attacks
Training a classifier on packet sizes and timing to guess what a conversation is about
Batching & KV caching Serving tricks that process many users at once and avoid recomputing work already done.
Quantization Storing a model's numbers with fewer bits so it's smaller and faster, at a small cost in accuracy.
Local inference runtimes Programs that run downloaded model files on your own computer instead of a remote service.
Speculative decoding A small, fast model guesses the next few tokens and the big model checks them all at once: fewer slow steps, with output identical under greedy decoding and the same distribution when sampling.
Model supply chain Everything you didn't build yourself (model files, datasets, libraries, tool packages) can carry an attack; checking where it came from and loading it safely is supply-chain security.