SZRouter is a self-hosted, multi-tenant AI token platform with frontend, admin panel, OpenAI-compatible API gateway, async worker, PostgreSQL/pgvector, Redis/BullMQ, and Nginx/Let's Encrypt all in a single TypeScript monorepo.

Stars

92

7-day growth

+1

Forks

1

Open issues

0

License

No data

Last updated

2026-07-23

AI repository intelligence
FR-AI / ANALYSIS

Why it is worth attention

It provides a complete, Docker-ready solution for running a production-grade AI token service with billing, RAG, agent marketplace, and workflow capabilities, all in one codebase.

Who it is for

  • Developers building AI token or API gateway platforms
  • System administrators deploying self-hosted AI services
  • Startups needing a multi-tenant AI billing and access system
  • Researchers requiring a RAG infrastructure with vector search

Use cases

  • Running a paid AI token service with user registration, API keys, and billing
  • Offering an OpenAI-compatible API gateway with rate limiting and channel selection
  • Building a knowledge base Q&A feature using RAG with PDF/DOCX parsing
  • Creating an agent marketplace and workflow automation for end users

Strengths

  • All-in-one monorepo reducing integration complexity
  • One-command Docker setup with demo data for quick evaluation
  • OpenAI-compatible API enabling drop-in replacement for existing apps
  • Built-in RAG with pgvector, hybrid search, and reranking

Considerations

  • Proprietary license requires custom license before public distribution
  • Requires Docker, PostgreSQL 16+pgvector, and Redis, increasing infrastructure dependencies
  • Security hardening (secret rotation, KMS, SSO) is needed before production use

README quick start

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

Description

https://szrouter.shop/

Related repositories

Similar projects matched by category, topics, and programming language.

TanStack
Featured
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 DevelopmentFrontend Frameworks
14,861
vercel-labs
Featured
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.

Developer ToolsCode Quality & Build
1,985
Jakubantalik
Featured
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 & Machine LearningAI Agents
1,191