@basisoasis/llm-intel

中文文档
1.0.102发布于 2026/11/02MITTypeScriptESM + CJS构建来源已验证近 30 天下载 2494

Source model capabilities and pricing from OpenRouter for cost-aware development without hardcoded data tables

原始使用文档
文档目录14 节
  1. Features
  2. Installation
  3. Usage
  4. Server ( LLMIntel )
  5. Standalone function
  6. Browser / SPA ( LLMIntelClient )
  7. API Reference
  8. LLMIntel (server)
  9. LLMIntelClient (browser)
  10. getModelInfo(modelId, opts) (standalone)
  11. Caching
  12. Configuration
  13. Providers
  14. License

llm-intel

Model intelligence for every LLM.

llm-intel sources model metadata and pricing from OpenRouter, so you can look up capabilities and calculate token costs without maintaining your own data tables.

Features

  • Look up any model's capabilities, context window, and pricing by ID
  • Calculate token costs with exact precision (powered by bignumber.js)
  • Two purpose-built APIs: a server client (fetches from OpenRouter) and a browser client (reads pre-fetched JSON)
  • Three-tier caching: memory -> disk -> network
  • Full TypeScript support with generated ModelId types

View Demo →

Installation

# npm
npm install @basisoasis/llm-intel

# pnpm
pnpm add @basisoasis/llm-intel

# yarn
yarn add @basisoasis/llm-intel

# bun
bun add @basisoasis/llm-intel

Usage

Server (LLMIntel)

Use this in Node.js / server-side environments. It fetches model data from OpenRouter, with disk and memory caching built in.

import { LLMIntel } from "@basisoasis/llm-intel";

// Instantiate a provider client
const client = await LLMIntel.create({ provider: 'openrouter' });

// Resolve a model by ID
const model = await client.getModel(
  'anthropic/claude-4.6-sonnet-20260217'
);

if (!model) throw new Error('Model not found!');

const cost = client.calculateCost(model, {
  inputTokens: 20_000,
  outputTokens: 1700,
});

console.log(client.formatCostResult(cost));
/* {
  inputCost: "$0.06",
  outputCost: "$0.03",
  cacheReadCost: null,
  cacheWriteCost: null,
  imageCost: null,
  requestCost: null,
  totalCost: "$0.09",
  currency: "USD",
  warnings: [],
} */

Standalone function

For one-off lookups without instantiating a client:

import { getModelInfo } from "@basisoasis/llm-intel";

const result = await getModelInfo("anthropic/claude-3-5-sonnet", {
  provider: "openrouter",
  apiKey: process.env.OPENROUTER_API_KEY,
});

Browser / SPA (LLMIntelClient)

Use this when you already have the model JSON (e.g. fetched server-side and passed to a SPA, or bundled at build time). No API key required.

import { LLMIntelClient } from "@basisoasis/llm-intel/client";

// Hydrate from a URL your server exposes
const client = new LLMIntelClient({
  models: "/api/models", // returns ModelsResult JSON
  cacheTtl: 5 * 60 * 1000, // 5 minutes
});

// Or hydrate statically from a pre-loaded array
const client = new LLMIntelClient({ models: modelDataArray });

const model = await client.getModel("google/gemini-2.5-pro");
if (!model) throw new Error('Model not found!');

const cost = client.calculateCost(model, {
  inputTokens: 2000,
  outputTokens: 800,
});

console.log(client.formatCost(cost.inputCost));  // $0.0025
console.log(client.formatCost(cost.outputCost)); // $0.008
console.log(client.formatCost(cost.totalCost));  // $0.01

API Reference

LLMIntel (server)

MethodDescription
LLMIntel.create(opts)Creates a validated client instance. Validates config upfront.
client.getModels()Returns all available models (ModelsResult).
client.getModel(modelId)Returns a single model by ID, or null if not found.
client.calculateCost(model, tokens, currency?)Calculates prompt/completion/total cost.
client.formatCost(amount, currency?)Formats a BigNumber as a currency string (e.g. "$5.12").
client.formatCostResult(result)Formats all line items in a CostResult to strings.

LLMIntelClient (browser)

Same getModel, getModels, calculateCost, formatCost, and formatCostResult methods. Takes either a URL or a pre-loaded ModelData[] array.

getModelInfo(modelId, opts) (standalone)

Fetches a single model without creating a client. Useful for serverless functions or scripts.

Caching

LLMIntel uses a three-tier cache:

  1. Memory: fastest; per-instance, invalidated by TTL
  2. Disk: survives process restarts
  3. Network: fetches fresh data from OpenRouter

Configure the TTL via cacheTtl in milliseconds (default: 86_400_000 — 24 hours).

LLMIntelClient uses memory caching only (no disk access in the browser).

Configuration

All options are optional — the library falls back to environment variables and then built-in defaults.

LLMIntel.create({
  provider: "openrouter",
  openRouterApiKey: process.env.LLM_INTEL_OPEN_ROUTER_API_KEY,
  cacheTtl: 86_400_000,
  cacheDir: ".cache",
});
OptionEnv varDefaultDescription
providerLLM_INTEL_PROVIDER"openrouter"Data source to use. See Providers.
openRouterApiKeyLLM_INTEL_OPEN_ROUTER_API_KEY—Your OpenRouter API key. Required when using the openrouter provider.
cacheTtlLLM_INTEL_CACHE_TTL86_400_000 (24 hours)How long cached model data is considered fresh, in milliseconds.
cacheDirLLM_INTEL_CACHE_DIR{cwd}/.cacheDirectory used for disk caching.

Providers

Currently, OpenRouter is the only supported provider. The library has been designed with a provider abstraction layer, so support for additional data sources can be added in the future without breaking changes to the public API.

ProviderStatus
OpenRouter✅ Supported
Others🗓 Planned

License

MIT

版本与发布记录

@basisoasis/llm-intel 共发布 100 个版本,首次发布于 2026/05/22;过去 12 个月发布了 100 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
1.0.102latest2026/11/025 天前
1.0.1012026/10/308 天前
1.0.1002026/10/2414 天前
1.0.992026/10/2315 天前
1.0.982026/10/2216 天前
1.0.972026/10/2216 天前

关于 @basisoasis/llm-intel 的常见问题

@basisoasis/llm-intel 是什么?

Source model capabilities and pricing from OpenRouter for cost-aware development without hardcoded data tables

如何安装 @basisoasis/llm-intel?

在项目目录运行 npm install @basisoasis/llm-intel,或使用 pnpm add / yarn add / bun add。

@basisoasis/llm-intel 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@basisoasis/llm-intel 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@basisoasis/llm-intel 可以商用吗?

@basisoasis/llm-intel 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@basisoasis/llm-intel 的下载量有多少?

根据 npm 官方下载统计,@basisoasis/llm-intel 在 2026/10/08 – 2026/11/06 这 30 天内被下载 2,494 次,日均约 83 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@basisoasis/llm-intel 还在维护吗?

最新版本 1.0.102 发布于 2026/11/02(5 天前);至今共发布 100 个版本,其中过去 12 个月发布了 100 个;首次发布于 2026/05/22。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。