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, Tokenify, DeepSeek, fal & Runware — lowest price per token, every time. Built for the Vercel AI SDK.

ai-lcr · live routing LIVE
CHEAPEST-FIRST LISTsaving −50%calllcr("smart")Tokenify$0.15 / 1M input· −50%● servingDeepSeek direct$0.30 / 1M inputFlash peak input: Tokenify saves 50% vs DeepSeek direct.

At peak, Tokenify costs 50% less than DeepSeek direct for V4.1 Flash fresh input and output. ai-lcr takes the cheapest healthy provider and reroutes to the next one when it fails. 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, DEFAULT_PROVIDERS } from "ai-lcr";
import { generateText } from "ai";
import { createOpenAICompatible } from "@ai-sdk/openai-compatible";
import { createDeepSeek } from "@ai-sdk/deepseek";

const tokenify = createOpenAICompatible({
  name: "tokenify",
  baseURL: DEFAULT_PROVIDERS.tokenify.baseURL,
  apiKey: process.env.TOKENIFY_API_KEY,
});
const deepseek = createDeepSeek({ apiKey: process.env.DEEPSEEK_API_KEY });

// DeepSeek V4.1 Flash peak rates; switch chains by time of day for off-peak.
const lcr = createLCR({
  autoSort: true,                  // order each model's providers cheapest-first
  models: {
    "deepseek-flash": [
      { model: tokenify("deepseek/deepseek-v4.1-flash"), cost: { input: 0.15, output: 0.60 } },
      { model: deepseek("deepseek-flash"), cost: { input: 0.30, output: 1.20 } },
    ],
  },
  onCost: ({ provider, costUsd }) => console.log(provider, costUsd),
});

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

See what you'd save.

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.

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, Tokenify, DeepSeek, DeepInfra, Kunavo, fal and Runware today, covering 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.