SZRouter 是一个可自托管的多租户 AI Token 平台,集成了前台、运营后台、OpenAI 兼容 API 网关、异步 Worker、PostgreSQL/pgvector、Redis/BullMQ 以及 Nginx/Let's Encrypt,全部位于同一个 TypeScript monorepo 中。

Stars

92

7 天增长

暂无数据

Fork 数

1

开放 Issue

0

开源协议

暂无数据

最近更新

2026-07-23

AI 仓库情报摘要
FR-AI / ANALYSIS

为什么值得关注

它提供了一个完整的、Docker 就绪的解决方案,用于运行生产级的 AI Token 服务,包含计费、RAG、Agent 市场和流程引擎,所有组件都在一个代码库中。

适合谁使用

  • 构建 AI Token 或 API 网关平台的开发者
  • 部署自托管 AI 服务的系统管理员
  • 需要多租户 AI 计费和访问控制的初创公司
  • 需要带有向量搜索的 RAG 基础设施的研究人员

典型使用场景

  • 运行付费 AI Token 服务,支持用户注册、API Key 和计费
  • 提供 OpenAI 兼容的 API 网关,具备限流和渠道选择
  • 使用 RAG 构建知识库问答功能,支持 PDF/DOCX 解析
  • 创建 Agent 市场和用户工作流自动化

项目优势

  • 一体化 monorepo 减少集成复杂度
  • 一键 Docker 启动,含演示数据,便于快速评估
  • OpenAI 兼容 API,可直接替换现有应用
  • 内置 RAG,支持 pgvector、混合检索和重排序

使用前须知

  • 专有许可证,公开发布前需添加自定义许可证
  • 依赖 Docker、PostgreSQL 16+pgvector 和 Redis,增加基础设施要求
  • 生产前需进行安全加固(密钥轮换、KMS、SSO)

README 快速开始

SZRouter

SZRouter 是一个可自托管的多租户 AI Token 平台:前台、运营后台、OpenAI Compatible API Gateway、异步 Worker、PostgreSQL/pgvector、Redis/BullMQ 与 Nginx/Let's Encrypt 都包含在同一个 TypeScript monorepo 中。

能力概览

  • Web 前台:注册登录、API Key、充值订单/卡密、模型广场、价格中心、流式 Playground、知识库与引用问答、Agent 市场、Workflow、组织租户、数据导出。
  • Admin 后台:管理员登录、用户/模型/渠道/订单/卡密管理、调用日志、内容审核、代理与提现、组织财务、月结/PDF 账单、告警、后台任务、审计日志与平台总览。
  • Gateway:API Key 鉴权、用户/组织余额预扣和结算、Token/工具/Agent 计费、Redis 限流、月度额度、加权渠道选择、熔断与失败回退、SSE、内容审核。
  • RAG:PDF/DOCX/TXT/MD 解析、1536 维 Embedding、pgvector HNSW、向量+全文混合检索、本地 Rerank 和来源引用。
  • Worker:邮件、Webhook 重试、导出、文档解析与 Embedding、知识库/Agent 评估、月报/PDF 账单、对账、告警与日志清理。

目录

token-factory/
├── web/                 Next.js 用户前台(3000)
├── admin/               Next.js 管理后台(3001)
├── gateway/             Express API Gateway(8000)
├── worker/              BullMQ Worker / Scheduler
├── packages/database/   Prisma Client、Schema、pgvector SQL
├── nginx/               三域名反向代理与 TLS 配置
├── docs/                API、架构和部署文档
├── docker-compose.yml
└── docker-compose.prod.yml

一键本地启动

前置条件:Docker 24+ 与 Docker Compose v2。

cp .env.example .env
# 至少修改 ADMIN_PASSWORD、JWT_SECRET、API_KEY_PEPPER 和数据库密码
docker compose up -d --build

服务地址:

首次启动会自动创建数据库表、pgvector 索引与演示数据。演示用户为 demo@szrouter.local / demo123456。未配置 OPENAI_API_KEY 时使用内置 Mock 渠道,便于完整验证登录、API Key、余额计费和 SSE;配置真实 Key 后执行 docker compose restart gateway worker 并重新运行 docker compose exec gateway npm run db:seed

查看状态与日志:

docker compose ps
docker compose logs -f gateway worker
curl http://localhost:8000/health

停止服务(保留数据):

docker compose down

非 Docker 开发

本机需要 Node.js 20+、PostgreSQL 16 + pgvector、Redis 7。

cp .env.example .env
# 把 DATABASE_URL / REDIS_URL 的主机名改为 localhost
npm install
npm run prisma:generate
npm run db:push
npm run db:seed
npm run dev

质量检查:

npm test
npm run typecheck
npm run build

OpenAI Compatible API

创建 API Key 后:

curl http://localhost:8000/v1/chat/completions \
  -H "Authorization: Bearer sz_your_key" \
  -H "Content-Type: application/json" \
  -d '{
    "model":"gpt-4o-mini",
    "stream":true,
    "messages":[{"role":"user","co

项目描述

https://szrouter.shop/

相关仓库与替代方案

根据分类、Topic 和编程语言匹配的相似项目。

TanStack
精选
TanStack GitHub avatar

router

TanStack Router is a type-safe, data-driven React router with built-in caching, prefetching, and nested layouts, while TanStack Start extends it into a full-stack SSR framework.

Web 开发前端框架
14,861
vercel-labs
精选
vercel-labs GitHub avatar

scriptc

scriptc compiles ordinary TypeScript into small, fast native executables without needing Node.js, V8, or any JavaScript runtime in the binary.

开发者工具代码质量与构建
1,985
Jakubantalik
精选
Jakubantalik GitHub avatar

thinking-orbs

A React component library that renders six hand-tuned animated thought orb loading indicators on a plain 2D canvas, with two purpose-tuned sizes and automatic theme detection for AI and agent UIs.

AI 与机器学习AI 智能体
1,191