JustujuAI, layer by layer.Open in the interactive map

Model APIs & routers

Paying per token to send requests to a hosted model, either directly to a provider or through a router that picks among many providers.

Layer 6 · Inference & Optimization · Run time · reviewed 2026-10-30

Read first: Tokens & tokenization.

D1 · StoryFor young children and total beginners

Guess first: what does the router do when one provider is down?

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.

Like a taxi app for AI

  1. Your app: sends a message
  2. The router: picks which company
  3. AI company: runs the model
  4. Answer back: plus a tiny bill

Like: A taxi app that picks which company sends the car.

D2 · PictureFor curious beginners

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.

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.

D4 · MechanismFor practitioners

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.

Try the interactive version in the map.

Things to try

# rates in $ per million tokens (illustrative)
tokens_in  = input_tokens  * workload   # chat 1, agent ~4, multi-agent ~15
tokens_out = output_tokens * workload
prefix = tokens_in * cached_share
fresh  = tokens_in - prefix
hits   = prefix * hit_rate
misses = prefix - hits
discount = 0.5 if batch else 1
cost = discount * (fresh  * in_price
                 + hits   * in_price * read_x     # e.g. 0.1
                 + misses * in_price * write_x    # e.g. 1.25
                 + tokens_out * out_price) / 1_000_000
per_day   = cost * requests_per_day
per_month = per_day * 30
# caching beats no caching when hit_rate * read_x + (1 - hit_rate) * write_x < 1

Trade-offs

D5 · FrontierFor experts

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).

Examples as of 2026-10-30

Sources

  1. OpenAI API reference: Chat Completions (2023)
  2. OpenRouter documentation: Quickstart (2024)
  3. vLLM documentation: OpenAI-Compatible Server (2025)
  4. Pricing: prompt caching and batch processing (Claude API documentation) (2026-10-15)
  5. Prompt caching (Claude API documentation) (2026-10-15)
  6. Batch API guide (OpenAI API documentation) (2026-10-15)
  7. Prompt caching guide (OpenAI API documentation) (2026-10-15)
  8. How we built our multi-agent research system (Anthropic) (2025-06-13)
  9. How is ChatGPT's behavior changing over time? (Chen, Zaharia, Zou) (2023-07-18)
  10. Defeating Nondeterminism in LLM Inference (Thinking Machines Lab) (2025-09-10)
  11. Extended thinking (Claude API documentation) (2026)

How it connects

More in Layer 6 · Inference & Optimization