Skip to content

llm-portsProvider-agnostic LLM architecture for TypeScript

The library that assumes you're running LLMs in production at cost, not in a demo. Cost gating, fallback chains, capability factories, tool-use security primitives.

60 seconds

1. Configure providers in .env:

bash
LLM_PROVIDER_FAST=anthropic|claude-haiku-4-5|cost:5/day
LLM_PROVIDER_SMART=anthropic|claude-sonnet-4-6-20250514|cost:50/day
LLM_TASK_ROUTE_TRIAGE=fast,smart

2. Create the port once at app start:

ts
import { createRegistryFromEnv } from "@llm-ports/core";
import { createAnthropicAdapter } from "@llm-ports/adapter-anthropic";

export const llm = createRegistryFromEnv({
  adapters: {
    anthropic: createAnthropicAdapter({ apiKey: process.env.ANTHROPIC_API_KEY! }),
  },
}).getPort();

3. Use anywhere in your codebase, no SDK imports:

ts
const result = await llm.generateText({
  taskType: "triage",
  prompt: "Classify this email: ...",
});

The registry picks the model per task, enforces the cost cap, walks to the next provider when a budget is exhausted, and reports per-call latency and USD cost. (In v0.1, fallback walks the chain on budget gating today — runtime-error fallback ships in v0.2; see the multi-provider guide, or the v0.1 status page for the full inventory of what's stable and what's not.)

How it relates to other tools

ToolHow llm-ports relates
Vercel AI SDKVercel unifies provider calls. llm-ports adds registry, fallback chains, USD cost gating, validation recovery, and capability factories on top. Use @llm-ports/adapter-vercel to keep your existing setup.
LiteLLMPython-first HTTP proxy. llm-ports is TypeScript in-process — zero network hop, no extra service to deploy. Talks to LiteLLM via the OpenAI adapter with baseURL.
PortkeyCommercial hosted gateway. llm-ports is MIT, in-process, no vendor lock-in. The tradeoff: Portkey ships a hosted UI; llm-ports does not.
LangChain.jsLangChain is a framework. llm-ports is a utility. Wrap LangChain LLM calls with a port for budget gating without adopting the whole framework.
LlamaIndex.TSLlamaIndex is retrieval-first. llm-ports handles LLM invocation; bring your own retrieval. They compose cleanly.
MastraMastra is opinionated agent-first with built-in memory. llm-ports is unopinionated primitives beneath that layer.

Read the full positioning →

MIT License