可配置的大语言模型 API 中继服务器,支持 OpenRouter、NVIDIA NIM、OpenAI、Anthropic、DeepSeek、Groq 等提供商。兼容 OpenAI 和 Anthropic API 接口。
- 多提供商支持:API 接入 + 网页反代(ChatGPT)
- 智能路由:模型别名、自动映射、工具调用降级
- 密钥管理:轮询/随机/加权选择,限速冷却
- 完整流式输出:OpenAI / Anthropic 格式双向 SSE
- 管理面板:Vue 3 SPA,支持中英文 i18n、移动端适配、浅色/深色主题
- 用户管理:支持 OAuth SSO(GitHub/Google)和本地账号,超级管理员权限
- 请求日志:SQLite 持久化,支持完整请求/响应内容查看、错误详情
- Gist 同步:GitHub Gist 备份配置,多设备同步
- Docker / Windows 单文件 / 源码 三种部署方式
- Python 3.11+(推荐 Python 3.12)
⚠️ Python 3.10 及以下版本可能因依赖包不兼容而无法运行。
- 前往 Releases 下载
MonoRelay-Windows-x64.zip - 解压,编辑
config.yml填入 API 密钥 - 双击
启动.bat,浏览器打开 http://localhost:8787
cp config.yml.example config.yml
docker compose up -dgit clone https://github.com/Excurs1ons/MonoRelay.git
cd MonoRelay
pip install -r requirements.txt
cp config.yml.example config.yml
python -m backend.main编辑 config.yml,核心配置项:
server:
host: "0.0.0.0"
port: 8787
access_key: "your-secret-key" # 请修改
public_host: "https://your-domain.com" # 公网访问地址(可选)
sso:
enabled: true
provider: "github" # github, google, prismaauth
github_client_id: "your-github-client-id"
github_client_secret: "your-github-client-secret"
google_client_id: "your-google-client-id"
google_client_secret: "your-google-client-secret"
providers:
openrouter:
enabled: true
base_url: "https://openrouter.ai/api/v1"
keys:
- key: "sk-or-v1-xxx"
label: "main"
headers:
HTTP-Referer: "https://your-site.com"
X-Title: "Your App"
chatgpt_web:
enabled: false
provider_type: "web_reverse"
keys:
- key: "your-chatgpt-access-token"
web_reverse:
pow_difficulty: "00003a"
conversation_only: false完整配置模板见 config.yml.example。
启动后访问 **http://localhost:8787**,输入 access_key 登录。
| 模块 | 说明 |
|---|---|
| 仪表盘 | 请求数、错误率、Token 消耗、模型统计、API 地址 |
| 提供商 | 添加/编辑/测试提供商,配置模型白名单 |
| 请求日志 | SQLite 持久化的请求详情,支持完整内容查看和错误分析 |
| 用户管理 | 管理用户账号、权限、超级管理员设置 |
| 设置 | 系统设置、SSO 配置、数据清空、主题切换 |
| 配置同步 | GitHub Gist 备份与恢复 |
| 配置文件 | 在线编辑 config.yml,保存后热重载 |
管理面板支持浅色/深色主题切换,点击右上角主题按钮即可切换。
支持 GitHub、Google OAuth 登录,在设置页面配置 SSO 后即可使用。
请求日志支持查看完整的请求和响应内容,错误日志默认展开显示。
FastAPI 自动生成 Swagger 文档,启动后访问 http://localhost:8787/docs 查看完整接口列表和在线测试。
MonoRelay/
├── backend/ # FastAPI 后端
│ ├── main.py # 入口、路由、认证
│ ├── config.py # 配置管理(热重载)
│ ├── models.py # Pydantic 数据模型
│ ├── key_manager.py # 密钥轮换与冷却
│ ├── router.py # 模型路由引擎
│ ├── logger.py # SQLite 请求日志
│ ├── stats.py # 统计与费用估算
│ ├── sync.py # Gist 同步
│ ├── secrets.py # 敏感信息管理(SQLite)
│ ├── auth.py # 用户认证和授权
│ ├── proxy/ # OpenAI / Anthropic 格式处理
│ └── web_reverse/ # ChatGPT 网页反代
├── frontend/ # Vue 3 管理面板
│ ├── src/
│ │ ├── views/ # 页面组件
│ │ ├── components/ # 公共组件
│ │ ├── stores/ # 状态管理
│ │ └── api.js # API 调用
├── data/ # 运行时数据(已 gitignore)
├── docs/ # 文档
│ └── LESSONS_LEARNED.md # 开发经验教训
├── config.yml.example # 配置模板
└── .github/workflows/ # 自动构建发布
推送 v*.*.* 格式的 tag 即可触发 GitHub Workflow 自动构建 Windows 可执行文件并发布 Release:
git tag -a v0.0.3 -m "Release v0.0.3"
git push origin --tags也可本地打包:
bash scripts/build.sh # Linux/macOS
.\scripts\build.ps1 # Windows在 config.yml 中设置 public_host:
server:
public_host: "https://your-domain.com"系统会自动生成正确的 API 地址。
在设置页面配置 SSO provider 和密钥,或直接编辑 config.yml:
sso:
enabled: true
provider: "github"
github_client_id: "your-client-id"
github_client_secret: "your-client-secret"在请求日志页面,点击日志条目展开查看。错误日志默认显示完整内容,普通日志可按需查看。
在设置页面或仪表盘页面点击"清空"按钮即可。
点击右上角的主题按钮(太阳/月亮图标)即可切换浅色/深色主题。
sudo bash scripts/service_install.sh# 查看状态
sudo systemctl status monorelay
# 查看日志
sudo journalctl -u monorelay -f
# 重启
sudo systemctl restart monorelay
# 停止
sudo systemctl stop monorelay
# 卸载
sudo bash scripts/service_uninstall.sh# 后台启动
./start-bg.sh start
# 查看状态
./start-bg.sh status
# 重启
./start-bg.sh restart
# 停止
./start-bg.sh stop# 1. 复制配置
cp config.yml.example config.yml
# 2. 编辑配置(填入 API Key)
vim config.yml
# 3. 启动
docker compose up -d
# 4. 查看日志
docker compose logs -f
# 5. 停止
docker compose down# 构建镜像
docker compose build
# 启动(后台)
docker compose up -d
# 启动(前台调试)
docker compose up
# 查看日志
docker compose logs -f monorelay
# 重启
docker compose restart monorelay
# 停止
docker compose down
# 查看状态
docker compose ps| 变量 | 说明 | 默认值 |
|---|---|---|
TZ |
时区 | Asia/Shanghai |
Docker 部署会自动创建 monorelay-data 卷,持久化存储:
- 用户数据 (
data/users.db) - 请求日志 (
data/requests.db) - 统计数据 (
data/stats.json) - 配置文件 (
data/config.yml)
# 安装依赖
npm install -g pm2
# 启动
pm2 start "python -m backend.main" --name monorelay
# 查看状态
pm2 status
# 查看日志
pm2 logs monorelay
# 重启
pm2 restart monorelay
# 停止
pm2 stop monorelay
# 开机自启
pm2 save
pm2 startup# 安装依赖
pip install -r requirements.txt
# 启动
python -m backend.main
# 指定端口
python -m backend.main --port 9000
# 指定配置文件
python -m backend.main --config /path/to/config.yml| 端口 | 服务 |
|---|---|
| 8787 | MonoRelay API |
| 9090 | Sing-box Clash API |
MIT