Ubinity

开源项目 · v2.3.1 · MPL-2.0 · NODE.JS >= 22

用一个调用契约,统一所有 LLM 供应商。

@ubinity/node-llm 是轻量零臃肿的 Node.js (>=22) 开源库,将 OpenAI、兼容服务端(DeepSeek / Qwen / Ollama)、Anthropic 与 Gemini / Vertex AI 标准化为统一请求、统一 OpenAI 兼容响应与统一错误类型(NodeLlmError),同时支持 API Key 与官方订阅客户端调用。

$ npm install @ubinity/node-llm
const { completion } = require('@ubinity/node-llm');

// Same calling contract for API keys or official subscriptions
const reply = await completion({
  model: 'anthropic/claude-haiku-4-5',
  auth: 'subscription', // or omit for API key
  timeout: 120000,
  messages: [
    { role: 'system', content: 'Answer in one concise sentence.' },
    { role: 'user', content: 'What is a vendored dependency?' }
  ]
});

console.log(reply.auth, reply.choices[0].message.content);

核心设计优势

API Key 与官方订阅(auth: "subscription")双支持

既可通过可选 peer SDK 走 API Key,也可通过 Claude Code、Codex、Antigravity CLI 官方客户端合规使用订阅额度(自动剥离 API Key 环境变量防误计费,支持 Windows WSL)。

严格契约,绝不静默丢弃参数

任何当前模式不支持的参数都会立即抛出类型化的 NodeLlmError ("unsupported"),防止生产环境静默漂移。

内置生产级韧性能力

内置遵循 Retry-After 的指数退避重试、AbortSignal / 超时控制、LRU 客户端复用、Prompt Caching、统一推理 effort 档位与 Tool Calling 标准化。

Supported Model Prefixes & Auth Modes

Model Prefix Protocol Auth Modes
openai/ · gpt* openai API key or Codex CLI (subscription)
deepseek/ · qwen/ · dashscope/ openai API key
ollama/ · custom baseURL openai None / optional
anthropic/ · claude* anthropic API key or Claude Code CLI (subscription)
gemini/ · google/ google API key or Antigravity CLI (subscription)
vertex_ai/ vertex_ai Google Cloud credentials
antigravity/<id> subscription Antigravity CLI (subscription only)

明确的设计边界(Contract v1)

  • 要求 Node.js 22 及以上版本,各厂商 SDK 为按需安装的 optional peerDependencies。
  • 每次调用返回单次完整归一化回复;stream: true 与多候选(n > 1)在 v1 契约中明确拒绝。
  • 完整 API 文档与变更日志以 GitHub 仓库为唯一真相源。

Built with the same deterministic engineering principles behind Ubinity Prompt Vault and Ubinity Ledger .