Least Cost Routing · for LLMs

The cheapest path for every model you call.

Route each call to the cheapest provider that can serve it, and fall back automatically when one fails. One config across OpenRouter, TokenMart, fal & Runware — lowest price per token, every time. Built for the Vercel AI SDK.

ai-lcr · live routing LIVE
CHEAPEST-FIRST LISTsaving −40%calllcr("smart")TokenMart$0.30 / 1M· −40%● servingOpenRouter$0.43 / 1MAnthropic API$0.50 / 1MServes the cheapest healthy provider — −40% vs the priciest route.

ai-lcr takes the cheapest healthy provider — saving ~40% — and when one goes offline, reroutes mid-flight to the next cheapest. No dropped calls.

Drop-in · one config

List your providers cheapest-first. Call it like any AI SDK model.

Mix a vendor's own official API with aggregators in one list. lcr("…") returns a standard model — it works with generateText, streamText, generateObject, tools and agents, unchanged.

import { createLCR } from "ai-lcr";
import { generateText } from "ai";

const lcr = createLCR({
  autoSort: true,                  // order each model's providers cheapest-first
  models: {
    "claude-sonnet-4-6": [
      { model: tokenmart("…"),  cost: { input: 2.55, output: 12.75 } },
      { model: openrouter("…"), cost: { input: 2.70, output: 13.50 } },
      { model: anthropic("…"),  cost: { input: 3.00, output: 15.00 } },
    ],
  },
  onCost: ({ provider, costUsd }) => log(provider, costUsd),  // real $ per call
});

// a standard AI SDK model — drop into streamText, generateObject, tools, agents
const { text } = await generateText({
  model: lcr("claude-sonnet-4-6"),
  prompt: "Explain Least Cost Routing in one sentence.",
});
What you'd save

Cut your bill up to 40% — without changing a line of app code.

The same model costs different amounts on different providers. Pick yours and your monthly spend — ai-lcr routes to the cheapest verified route and tracks the real cost per call.

$800saved / month
$9,600/ year

ai-lcr routes GPT-4.1 to TokenMartyou'd pay $1,200/mo instead of $2,000, a 40% cut.

Estimate: list price (OpenRouter) vs the cheapest verified route, blended input + output. Your real mix and volume shift the number — see the full table on Prices.

Same model, fully tested at a cheaper price

A discount is worthless if the provider quietly breaks the wire.

List price ≠ effective price. ai-lcr ships a zero-dependency probe that vets the things that actually cost you money or corrupt output — per model — so a cheaper route only gets ranked if it behaves. Results are live on the status page.

Tool calls
single + multi-step round-trips with content: null — the shape every agent loop sends
max_tokens honored
the cap actually bounds output, so you aren't billed past your limit
No hidden-prompt injection
flags providers that react to a system prompt you never sent
Token over-counting
compares reported tokens to a trusted baseline — >1.5× means the bill is inflated
Prompt caching
checks that cache_control produces a real cache_read on repeats
Native features intact
route to a vendor's own API — no markup, no silently-stripped capabilities
Zero markup, your keys
Routes straight to each vendor's own API with your own keys — no proxy, no per-token fee, no lock-in.
115 models priced
Text, image & video routes compared per model. See the cheapest provider for each →
Automatic failover
When a provider errors — even mid-stream — traffic reroutes to the next cheapest healthy one.
Quarantines bad providers
A circuit breaker most fallback libraries skip: one that keeps failing is benched, not re-probed on every call — then auto-recovered.
Zero-config pricing
A bundled price table prices native-maker routes with no hand-typed cost — add discount for a flat-rate reseller.
Real cost tracking
An onCost callback fires the actual USD per call, so you can see and attribute every dollar.
Response cache, no service
An identical request replays in-process — zero latency, zero cost. In-memory by default, or bring your own Redis/KV.
FAQ

Questions, answered.

Does ai-lcr work with the Vercel AI SDK?

Yes. lcr("model-id") returns a standard AI SDK language model, so it drops straight into generateText, streamText, generateObject, tool calls and agents with no other code changes. ai-lcr only decides which provider serves the call.

How is ai-lcr different from OpenRouter or the Vercel AI Gateway?

Those are hosted proxies that sit between you and the model and add their own markup. ai-lcr is a client-side router you configure in your own app: it calls each vendor's own API directly, with your own keys, at zero markup. You list the providers for a model cheapest-first — mixing aggregators and native vendor APIs — and ai-lcr picks the cheapest healthy one per call.

What happens when a provider goes down?

ai-lcr automatically falls back to the next cheapest healthy provider for that model. Failover is streaming-safe, so a provider erroring mid-stream reroutes without dropping the call.

How does ai-lcr know a cheaper provider is actually safe to route to?

A discount is worthless if the provider quietly breaks the wire protocol. ai-lcr ships a zero-dependency probe that verifies tool calls, that max_tokens is honored, that there is no hidden-prompt injection, that tokens aren't over-counted versus a trusted baseline, and that prompt caching works. Results run daily and are published live on the status page.

Can I keep using my own API keys?

Yes. ai-lcr routes straight to each vendor's own endpoint using the keys you provide, so you keep your billing relationship, rate limits and native features. There is no ai-lcr account and no proxy in the middle.

Is ai-lcr free?

Yes. ai-lcr is MIT-licensed, free and open source. You pay the underlying providers directly at their own rates — ai-lcr adds no fee or markup.

Which providers and models are supported?

ai-lcr routes across OpenRouter, TokenMart, DeepInfra, fal and Runware today, covering 80+ text, image and video models. The cheapest provider for each model is listed on the prices page, and you can add any OpenAI-compatible provider yourself.

MIT · drop-in · zero lock-in

Stop paying list price for the same tokens.

One config across every provider, cheapest healthy route on every call, automatic failover, and the receipts to prove the discount is real. Add it in one line.