电话
每个LLM的模型智能.
电话 来源:元数据和定价模型 打开路透社,这样您就可以在不维护自己的数据表格的情况下,查阅能力并计算符号成本.
特征
- 查看任何模型的能力、上下文窗口和ID定价
- 精确地计算符号成本(由
bignumber.js(中文(简体) ) - 两个专有的API:a 服务器客户端 (Fetches from OpenRouter)和(Fetches from OpenRouter) (英语: 浏览器客户端 (阅读预选JSON)
- 三级缓存:内存 - > 磁盘 - > 网络
- 生成的完整类型脚本支持
ModelId类型
安装
# npm
npm install @basisoasis/llm-intel
# pnpm
pnpm add @basisoasis/llm-intel
# yarn
yarn add @basisoasis/llm-intel
# bun
bun add @basisoasis/llm-intel
使用量
服务器( U)LLMIntel(中文(简体) )
在 Node.js / 服务器侧环境中使用此功能 。 它从 OpenRouter 获取模型数据, 里面有磁盘和内存缓存 .
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: [],
} */
独立函数
对于一次性检查,而不对客户进行即时检查:
import { getModelInfo } from "@basisoasis/llm-intel";
const result = await getModelInfo("anthropic/claude-3-5-sonnet", {
provider: "openrouter",
apiKey: process.env.OPENROUTER_API_KEY,
});
浏览器 / SPA (LLMIntelClient(中文(简体) )
当您已经拥有了型号JSON( 例如获取服务器侧并传递到 SPA, 或在构建时捆绑) 时使用此功能 。 不需要 API 密钥 .
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 参考
LLMIntel (服务器)
| 方法 | 说明 |
|---|---|
LLMIntel.create(opts) | 创建有效的客户端实例 。 验证前面的配置 . |
client.getModels() | 返回所有可用的模型( E)ModelsResult) (中文(简体) ). |
client.getModel(modelId) | 以 ID 返回单一模式,或 null 如果找不到的话. |
client.calculateCost(model, tokens, currency?) | 计算迅速/完成/总费用. |
client.formatCost(amount, currency?) | 格式 a BigNumber 作为货币字符串(例如:. "$5.12") (中文(简体) ). |
client.formatCostResult(result) | 在a中格式化所有行项目 CostResult 用于字符串. |
LLMIntelClient (浏览器)
一样 getModel, (中文(简体) ), getModels, (中文(简体) ), calculateCost, (中文(简体) ), formatCost,以及 formatCostResult 方法。 。 。 使用 URL 或预装 ModelData[] 阵列.
getModelInfo(modelId, opts) (独立)
在不创建客户端的情况下获取单个模型。 用于无服务器函数或脚本 .
缓存
LLMIntel 使用三级缓存 :
- 内存 : 速度最快; 任意, TTL 无效
- 磁盘 : 幸存进程重新启动
- 网络 : 从 OpenRouter 获取新数据
配置 TTL 通过 cacheTtl 以毫秒计(默认值: 86_400_000 ——24小时.
LLMIntelClient 只使用内存缓存(浏览器中没有磁盘访问).
配置
所有选项都是可选的——库会倒回环境变量后再内置默认.
LLMIntel.create({
provider: "openrouter",
openRouterApiKey: process.env.LLM_INTEL_OPEN_ROUTER_API_KEY,
cacheTtl: 86_400_000,
cacheDir: ".cache",
});
| 选项 | 新闻 var | 默认 | 说明 |
|---|---|---|---|
provider | LLM_INTEL_PROVIDER | "openrouter" | 要使用的数据源 。 见 供应商。 。 。 . |
openRouterApiKey | LLM_INTEL_OPEN_ROUTER_API_KEY | —— 说 | 您的 OpenRouter API 密钥 。 使用时需要 openrouter 供养. |
cacheTtl | LLM_INTEL_CACHE_TTL | 86_400_000 (24小时) | 缓存的模型数据有多长被认为是新鲜的,以毫秒计. |
cacheDir | LLM_INTEL_CACHE_DIR | {cwd}/.cache | 用于磁盘缓存的目录 . |
供应商
目前, 打开路透社 是唯一支持的提供者。 库已设计出一个提供者抽象层,因此未来可以在不突破公共API更改的情况下添加对额外数据源的支持.
| 提供者 | 状态 |
|---|---|
| 打开路透社 | 获支持 |
| 其他人员 | 计划数 |
许可证
麻省理工学院