ssantosdanilo/ollama2api
Aggregate multiple Ollama instances into a unified OpenAI-compatible API with load balancing, health checks, auto discovery, and web management.
Platform-specific configuration:
{
"mcpServers": {
"ollama2api": {
"command": "npx",
"args": [
"-y",
"ollama2api"
]
}
}
}Add the config above to .claude/settings.json under the mcpServers key.
> Ollama 后端聚合网关 — 兼容 OpenAI API,多节点负载均衡,自动发现与管理
将多个 Ollama 实例聚合为统一的 OpenAI 兼容 API,支持智能负载均衡、健康检查、节点扫描发现和 Web 管理后台。
/v1/chat/completions + /v1/models,可直接对接 ChatGPT 前端、Cursor 等工具git clone https://github.com/yourname/ollama2api.git
cd ollama2api
docker-compose up -d访问 http://localhost:8001/admin 进入管理后台。
> 安全提示:首次部署后请立即在管理后台修改默认管理员密码。
python -m venv venv
source venv/bin/activate # Windows: venv\Scripts\activate
pip install -r requirements.txt
python main.py服务启动于 http://localhost:8001。
| 依赖 | 必须 | 说明 | |------|------|------| | Python 3.10+ | 是 | 运行环境 | | masscan | 否 | 高速端口扫描,未安装时回退纯 Python | | Xray | 否 | 代理支持,不需代理可忽略 |
运行时配置存储在 data/config.json,支持通过管理后台热修改:
| 配置项 | 默认值 | 说明 | |--------|--------|------| | request_timeout | 300 | 请求超时(秒) | | connect_timeout | 10 | 连接超时(秒) | | health_check_interval | 300 | 健康检查间隔(秒) | | max_retries | 3 | 请求最大重试次数 | | cooldown_threshold | 3 | 连续失败多少次后冷却 | | cooldown_duration | 300 | 冷却时长(秒) | | scanner_concurrency | 50 | 扫描并发数 | | masscan_rate | 5000 | masscan 发包速率 | | cleanup_offline_hours | 24 | 离线节点自动清理阈值(小时) |
完全兼容 OpenAI Chat Completions API:
# 聊天补全(流式)
curl http://localhost:8001/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer your-api-key" \
-d '{"model": "your-model", "messages": [{"role": "user", "content": "Hello"}], "stream": true}'
# 模型列表
curl http://localhost:8001/v1/models
# 健康检查
curl http://localhost:8001/health> 未配置 API Key 时无需 Authorization 头。
独
Loading reviews...