← 返回
内容创作 Key 中文

Ai Provider Bridge

One interface to call 6 AI providers. Swap models with a config change, not a code rewrite. Zero external dependencies.
一个接口调用6个AI提供商,换模型只需改配置,无需改代码,零外部依赖。
theshadowrose
内容创作 clawhub v1.0.3 1 版本 100000 Key: 需要
★ 0
Stars
📥 672
下载
💾 7
安装
1
版本
#api#integration#latest#multi-model#providers#routing

概述

AI Provider Bridge — Unified API for Anthropic/OpenAI/Google/xAI/Mistral/Ollama

One interface to call 6 AI providers. Swap models with a config change, not a code rewrite. Zero external dependencies.


Unified interface for 6 AI providers. One function call, any model.

Supported Providers

ProviderModelsAPI Key Env Var
----------------------------------
AnthropicClaude Opus, Sonnet, HaikuANTHROPIC_API_KEY
OpenAIGPT-4o, GPT-4, GPT-3.5OPENAI_API_KEY
GoogleGemini Pro, Gemini FlashGOOGLE_API_KEY
xAIGrokXAI_API_KEY
MistralMistral Large, Medium, SmallMISTRAL_API_KEY
OllamaAny local modelNone (local)

Usage

const { AIBridge } = require('./src/ai-bridge');

const ai = new AIBridge({
  currentModel: 'anthropic/claude-sonnet-4-20250514',
  anthropicApiKey: process.env.ANTHROPIC_API_KEY,  // only needed for Anthropic models
  openaiApiKey:    process.env.OPENAI_API_KEY,      // only needed for OpenAI models
  googleApiKey:    process.env.GOOGLE_API_KEY,      // only needed for Google models
  xaiApiKey:       process.env.XAI_API_KEY,         // only needed for xAI models
  mistralApiKey:   process.env.MISTRAL_API_KEY,     // only needed for Mistral models
  ollamaHost:      'http://127.0.0.1:11434'         // optional, default shown
});

const response = await ai.sendMessage('What is the capital of France?');
console.log(response);

Switching Providers

Change the model — provider is inferred from the prefix:

// Switch from cloud to local Ollama
ai.setModel('ollama/llama3.1:8b');

// Same interface
const response = await ai.sendMessage('Same question, free model');

Model prefix → provider mapping:

  • anthropic/ → Anthropic API
  • openai/ → OpenAI API
  • google/ → Google Gemini API
  • xai/ → xAI Grok API
  • mistral/ → Mistral API
  • ollama/ → Local Ollama (no API key needed)

Zero Dependencies

Uses only Node.js built-in https and http modules. No npm install needed.


Changelog

v1.0.3

  • Fixed API usage examples — config object uses camelCase property names (anthropicApiKey, openaiApiKey, googleApiKey, xaiApiKey, mistralApiKey), not flat apiKey or env var names. Model prefix determines provider (anthropic/model-name). Clarified sendMessage() as the correct method name.

v1.0.2

  • Removed require('./token-compressor') reference entirely. TokenCompressor is now an inlined no-op pass-through class — no missing dependency, no external file needed. To enable compression, install the companion token-compressor skill and swap the class as noted in the code comments.
  • Removed automatic "Do not store or train on this data." appended to system prompts in OpenAI-compatible requests. This is the caller's responsibility — pass it via setSystemPrompt() if needed.

v1.0.1

  • TokenCompressor dependency made optional — no-op fallback added when ./token-compressor is not present. Bridge works without it; messages pass through uncompressed.
  • Removed buildSystemPrompt() and workspaceContext option. These allowed embedding workspace files into system prompts sent to external APIs — data exposure risk. Use setSystemPrompt() directly.
  • Added env: section to frontmatter declaring required API keys per provider. All optional — only keys for providers you use are needed.

⚠️ Disclaimer

This software is provided "AS IS", without warranty of any kind, express or implied.

USE AT YOUR OWN RISK.

  • The author(s) are NOT liable for any damages, losses, or consequences arising from

the use or misuse of this software — including but not limited to financial loss,

data loss, security breaches, business interruption, or any indirect/consequential damages.

  • This software does NOT constitute financial, legal, trading, or professional advice.
  • Users are solely responsible for evaluating whether this software is suitable for

their use case, environment, and risk tolerance.

  • No guarantee is made regarding accuracy, reliability, completeness, or fitness

for any particular purpose.

  • The author(s) are not responsible for how third parties use, modify, or distribute

this software after purchase.

By downloading, installing, or using this software, you acknowledge that you have read

this disclaimer and agree to use the software entirely at your own risk.

DATA DISCLAIMER: This software processes and stores data locally on your system.

The author(s) are not responsible for data loss, corruption, or unauthorized access

resulting from software bugs, system failures, or user error. Always maintain

independent backups of important data. This software does not transmit data externally

unless explicitly configured by the user.


Support & Links

------
🐛 Bug ReportsTheShadowyRose@proton.me
Ko-fiko-fi.com/theshadowrose
🛒 Gumroadshadowyrose.gumroad.com
🐦 Twitter@TheShadowyRose
🐙 GitHubgithub.com/TheShadowRose
🧠 PromptBasepromptbase.com/profile/shadowrose

Built with OpenClaw — thank you for making this possible.


🛠️ Need something custom? Custom OpenClaw agents & skills starting at $500. If you can describe it, I can build it. → Hire me on Fiverr

版本历史

共 1 个版本

  • v1.0.3 当前
    2026-03-29 17:21 安全

安全检测

腾讯云安全 (Keen)

安全,无风险
查看报告

腾讯云安全 (Sanbu)

suspicious
查看报告

🔗 相关推荐

content-creation

Baidu Wenku AIPPT

ide-rea
使用百度文库 AI 智能生成 PPT,自动根据内容选择模板。
★ 66 📥 46,185
content-creation

Humanizer

biostartechnology
消除AI写作痕迹,使文本更自然真实。基于维基百科"AI写作特征"指南,识别并修正夸张象征、宣传用语、肤浅-ing分析、模糊归因、破折号滥用、三项排比、AI词汇、负面平行结构及冗长连接词等模式。
★ 860 📥 199,712
developer-tools

APITester Agent-Driven API Testing

theshadowrose
测试 API 端点,记录响应;用简明英文编写测试,执行后得到格式化结果。代理驱动的 Postman 替代方案。
★ 0 📥 1,839