ai-lcr
Providers

Overview

ai-lcr doesn't ship provider clients — it routes across the AI SDK models you construct. Create each provider once with createOpenAICompatible, then list them cheapest-first.

ai-lcr doesn't ship provider clients — it routes across the AI SDK models you construct. Almost every provider is OpenAI-compatible, so you create each one once with createOpenAICompatible, then drop them into a cheapest-first list.

import { createOpenAICompatible } from "@ai-sdk/openai-compatible";

Supported providers

  • OpenRouter — widest coverage, the safe fallback.
  • TokenMart — cheap mainstream catalog.
  • DeepInfra — open-weights host.
  • Kunavo — discounted partner models; also image + video.
  • fal — image + video, via a media adapter.
  • Runware — cheap image generation, via a media adapter.

Any OpenAI-compatible endpoint works for text — the catalog above is just the ones with notes worth calling out. A model vendor's own official API (@ai-sdk/openai, @ai-sdk/anthropic, …) is also just another entry in a list.

For official SDKs, ai-lcr includes a dynamic native-provider loader so unused vendors remain optional:

import { createLCR, createOfficialProvider } from "ai-lcr";

const anthropic = await createOfficialProvider("anthropic");

const lcr = createLCR({
  autoPrice: true,
  models: {
    "claude-sonnet": [
      { model: anthropic("claude-sonnet-4-6"), label: "anthropic" },
    ],
  },
});

Supported native keys: anthropic, openai, google, xai, mistral, deepseek, cohere, groq, perplexity, fireworks, togetherai, cerebras, azure, google-vertex, and amazon-bedrock. Install only what you use, for example npm i @ai-sdk/anthropic.

createOfficialProvider does not force a provider-package major upgrade. It uses the createXxx factory exported by the package you already installed, so an app pinned to @ai-sdk/anthropic@2.x can stay there. If you already call createAnthropic({ apiKey }) yourself, that is functionally equivalent; the helper just centralizes package/env/factory lookup.

GLM / Z.ai currently does not have an official Vercel @ai-sdk/glm or @ai-sdk/zhipu provider package. Use its OpenAI-compatible endpoint with createOpenAICompatible, or a third-party provider package, and pass the model into createLCR the same way.

The last three serve image and video. Those aren't OpenAI-compatible text endpoints — you wire them with a media adapter (createFalMediaAdapter, …) and route them through createMediaLCR instead.

Putting them in one cheapest-first list

Each logical model lists every provider that serves it, cheapest-first. The same model is named differently per provider — that's exactly what the router maps:

import { createLCR } from "ai-lcr";

const lcr = createLCR({
  autoSort: true,
  models: {
    // one logical model → cheapest provider that serves it, with fallback
    "gemini-2.5-flash": [
      { model: tokenmart("gemini-2.5-flash"), label: "tokenmart", cost: { input: 0.3, output: 1.2 } },
      { model: kunavo("gemini-2.5-flash"), label: "kunavo", cost: { input: 0.3, output: 1.25 } },
      { model: openrouter("google/gemini-2.5-flash"), label: "openrouter", cost: { input: 0.3, output: 2.5 } },
    ],
    "deepseek-v4-flash": [
      { model: deepinfra("deepseek-ai/DeepSeek-V4-Flash"), label: "deepinfra", cost: { input: 0.27, output: 0.4 } },
      { model: openrouter("deepseek/deepseek-v4-flash"), label: "openrouter", cost: { input: 0.3, output: 0.5 } },
    ],
  },
  onCost: ({ provider, costUsd }) => console.log(`${provider}: $${costUsd.toFixed(6)}`),
});

Check each provider's live GET /v1/models for valid ids — catalogs change (a model can 502 on one provider while serving fine on another), which is the whole reason to keep more than one route per model.

On this page