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
| Provider | Models | API Key Env Var |
|---|
| Anthropic | Claude Opus, Sonnet, Haiku | INLINECODE0 |
| OpenAI |
GPT-4o, GPT-4, GPT-3.5 |
OPENAI_API_KEY |
| Google | Gemini Pro, Gemini Flash |
GOOGLE_API_KEY |
| xAI | Grok |
XAI_API_KEY |
| Mistral | Mistral Large, Medium, Small |
MISTRAL_API_KEY |
| Ollama | Any local model | None (local) |
Usage
CODEBLOCK0
Switching Providers
Change the model — provider is inferred from the prefix:
CODEBLOCK1
Model prefix → provider mapping:
- -
anthropic/ → Anthropic API - INLINECODE6 → OpenAI API
- INLINECODE7 → Google Gemini API
- INLINECODE8 → xAI Grok API
- INLINECODE9 → Mistral API
- INLINECODE10 → 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 Reports | TheShadowyRose@proton.me |
| ☕ Ko-fi |
ko-fi.com/theshadowrose |
| 🛒
Gumroad |
shadowyrose.gumroad.com |
| 🐦
Twitter |
@TheShadowyRose |
| 🐙
GitHub |
github.com/TheShadowRose |
| 🧠
PromptBase |
promptbase.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
技能名称: AI Provider Bridge — Anthropic/OpenAI/Google/xAI/Mistral/Ollama统一API
详细描述:
AI Provider Bridge — Anthropic/OpenAI/Google/xAI/Mistral/Ollama统一API
一个接口调用6家AI提供商。通过配置更改即可切换模型,无需重写代码。零外部依赖。
6家AI提供商的统一接口。一次函数调用,任意模型。
支持的提供商
| 提供商 | 模型 | API密钥环境变量 |
|---|
| Anthropic | Claude Opus、Sonnet、Haiku | ANTHROPICAPIKEY |
| OpenAI |
GPT-4o、GPT-4、GPT-3.5 | OPENAI
APIKEY |
| Google | Gemini Pro、Gemini Flash | GOOGLE
APIKEY |
| xAI | Grok | XAI
APIKEY |
| Mistral | Mistral Large、Medium、Small | MISTRAL
APIKEY |
| Ollama | 任意本地模型 | 无(本地) |
使用方法
javascript
const { AIBridge } = require(./src/ai-bridge);
const ai = new AIBridge({
currentModel: anthropic/claude-sonnet-4-20250514,
anthropicApiKey: process.env.ANTHROPICAPIKEY, // 仅Anthropic模型需要
openaiApiKey: process.env.OPENAIAPIKEY, // 仅OpenAI模型需要
googleApiKey: process.env.GOOGLEAPIKEY, // 仅Google模型需要
xaiApiKey: process.env.XAIAPIKEY, // 仅xAI模型需要
mistralApiKey: process.env.MISTRALAPIKEY, // 仅Mistral模型需要
ollamaHost: http://127.0.0.1:11434 // 可选,默认值如上
});
const response = await ai.sendMessage(法国的首都是哪里?);
console.log(response);
切换提供商
更改模型——提供商从前缀推断:
javascript
// 从云端切换到本地Ollama
ai.setModel(ollama/llama3.1:8b);
// 相同接口
const response = await ai.sendMessage(相同问题,免费模型);
模型前缀 → 提供商映射:
- - anthropic/ → Anthropic API
- openai/ → OpenAI API
- google/ → Google Gemini API
- xai/ → xAI Grok API
- mistral/ → Mistral API
- ollama/ → 本地Ollama(无需API密钥)
零依赖
仅使用Node.js内置的https和http模块。无需npm安装。
更新日志
v1.0.3
- - 修复了API使用示例——配置对象使用驼峰命名属性名(anthropicApiKey、openaiApiKey、googleApiKey、xaiApiKey、mistralApiKey),而非扁平化的apiKey或环境变量名。模型前缀决定提供商(anthropic/model-name)。澄清了sendMessage()为正确的方法名。
v1.0.2
- - 完全移除了require(./token-compressor)引用。TokenCompressor现在是一个内联的无操作透传类——无缺失依赖,无需外部文件。如需启用压缩,请安装配套的token-compressor技能,并按代码注释中的说明替换该类。
- 移除了在兼容OpenAI的请求中自动追加到系统提示的Do not store or train on this data.。这是调用者的责任——如有需要,请通过setSystemPrompt()传递。
v1.0.1
- - TokenCompressor依赖变为可选——当./token-compressor不存在时添加了无操作回退。Bridge无需它即可工作;消息以未压缩形式透传。
- 移除了buildSystemPrompt()和workspaceContext选项。这些选项允许将工作区文件嵌入发送到外部API的系统提示中——存在数据泄露风险。请直接使用setSystemPrompt()。
- 在frontmatter中添加了env:部分,声明每个提供商所需的API密钥。全部可选——仅需使用到的提供商的密钥。
⚠️ 免责声明
本软件按原样提供,不提供任何明示或暗示的担保。
使用风险自负。
- - 作者对因使用或滥用本软件而产生的任何损害、损失或后果概不负责——包括但不限于财务损失、数据丢失、安全漏洞、业务中断或任何间接/后果性损害。
- 本软件不构成财务、法律、交易或专业建议。
- 用户全权负责评估本软件是否适合其使用场景、环境和风险承受能力。
- 不保证准确性、可靠性、完整性或适用于任何特定目的。
- 作者不对第三方在购买后如何使用、修改或分发本软件负责。
下载、安装或使用本软件即表示您已阅读本免责声明,并同意完全自担风险使用本软件。
数据免责声明: 本软件在您的系统上本地处理和存储数据。作者不对因软件错误、系统故障或用户错误导致的数据丢失、损坏或未经授权访问负责。请始终保留重要数据的独立备份。除非用户明确配置,否则本软件不会将数据外部传输。
支持与链接
| |
|---|
| 🐛 错误报告 | TheShadowyRose@proton.me |
| ☕ Ko-fi |
ko-fi.com/theshadowrose |
| 🛒
Gumroad |
shadowyrose.gumroad.com |
| 🐦
Twitter |
@TheShadowyRose |
| 🐙
GitHub |
github.com/TheShadowRose |
| 🧠
PromptBase |
promptbase.com/profile/shadowrose |
基于OpenClaw构建——感谢您让这一切成为可能。
🛠️
需要定制功能? 自定义OpenClaw代理和技能起价500美元。只要您能描述,我就能构建。→
在Fiverr上雇佣我