基于快手万擎网关 · 多租户隔离 · 账户额度管控 · 两种方案可选
适合场景:需要 Web 管理后台、多租户 Key 管理、开箱即用的额度/限流/计费系统。
| 维度 | 实现 |
|---|---|
| Key 隔离 | 每用户/应用独立 API Key,互不可见 |
| 额度隔离 | 按 Key / Group 设置 token 日上限 + 月上限,超额 429 |
| 路由隔离 | 不同 Group 路由不同模型优先级(研发→万擎,客户→海外池) |
| 审计隔离 | 超级管理员 / 组管理员 / 普通用户三级权限 |
# New API 渠道配置
channels:
- name: "快手万擎-DeepSeek"
type: "openai"
base_url: "https://wanqing.kuaishou.com/v1"
key: "${WANQING_API_KEY}"
models: ["deepseek-chat", "deepseek-reasoner"]
groups: ["研发部", "产品部"] # 限定可用部门
- name: "快手万擎-混元"
type: "openai"
base_url: "https://wanqing.kuaishou.com/v1"
key: "${WANQING_API_KEY}"
models: ["hunyuan-turbo", "hunyuan-pro"]
- name: "Anthropic-Claude"
type: "anthropic"
base_url: "https://api.anthropic.com"
key: "${ANTHROPIC_API_KEY}"
models: ["claude-opus-4-8", "claude-sonnet-4-6"]
# docker-compose.yml
services:
postgres:
image: postgres:16
redis:
image: redis:7-alpine
new-api:
image: calciumion/new-api:latest
ports: ["3000:3000"]
environment:
SQL_DSN: "postgres://admin:${DB_PASSWORD}@postgres/apigateway"
REDIS_CONN_STRING: "redis://redis:6379"
SESSION_SECRET: ${SESSION_SECRET}
depends_on: [postgres, redis]
适合场景:已有自建用户体系,只需统一模型接入 + 负载均衡 + cost tracking + fallback。
| 机制 | 实现 |
|---|---|
| Virtual Key | 每个用户/应用生成独立 Key,关联到 Team |
| Team 隔离 | Team 级 budget + rpm/tpm 上限,超额自动拦截 |
| Model Access | 按 Team 限定可用模型列表 |
| Spend Tracking | 内置 dashboard,按 Key/Team/Model 查看费用 |
# LiteLLM proxy config.yaml
model_list:
- model_name: deepseek-chat
litellm_params:
model: openai/deepseek-chat
api_base: https://wanqing.kuaishou.com/v1
api_key: ${WANQING_API_KEY}
rpm: 1000
tpm: 5000000
- model_name: hunyuan-turbo
litellm_params:
model: openai/hunyuan-turbo
api_base: https://wanqing.kuaishou.com/v1
api_key: ${WANQING_API_KEY}
- model_name: claude-opus-4-8
litellm_params:
model: anthropic/claude-opus-4-8
api_key: ${ANTHROPIC_API_KEY}
litellm_settings:
fallbacks:
- deepseek-chat: qwen-max # 万擎挂了自动切备用
num_retries: 3
request_timeout: 600
general_settings:
master_key: ${LITELLM_MASTER_KEY}
database_url: "postgresql://..."
router_settings:
allowed_fails: 3
cooldown_time: 30 # 冷却 30 秒再重试
# 创建 Team + 分配额度
curl -X POST http://localhost:4000/team/new \
-H "Authorization: Bearer ${MASTER_KEY}" \
-d '{"team_alias":"rd-dept","models":["deepseek-chat","hunyuan-turbo"],"max_budget":100,"tpm_limit":500000}'
# 给小王发 Key
curl -X POST http://localhost:4000/key/generate \
-H "Authorization: Bearer ${MASTER_KEY}" \
-d '{"team_id":"rd-dept","key_alias":"wang-key","max_budget":30,"rpm_limit":20}'
# docker-compose.yml
services:
litellm:
image: ghcr.io/berriai/litellm:main-latest
ports: ["4000:4000"]
volumes:
- ./litellm_config.yaml:/app/config.yaml
environment:
DATABASE_URL: "postgresql://user:pass@postgres/litellm"
LITELLM_MASTER_KEY: ${LITELLM_MASTER_KEY}
STORE_MODEL_IN_DB: "true"
postgres:
image: postgres:16
| 维度 | New API | LiteLLM |
|---|---|---|
| GitHub | QuantumNous/new-api ⭐35K | BerriAI/litellm ⭐23K |
| 定位 | 一站式 API 网关 + 运营平台 | 轻量模型代理 + 统一接口 |
| 用户管理 | 内置 Web Admin,开箱即用 | 需自建或外挂用户系统 |
| Key 管理 | Group/Key 二级隔离 | Virtual Key + Team 隔离 |
| 额度管控 | 日/月 token 上限 + RPM | Team budget + tpm/rpm limit |
| 计费 | 基础用量统计 | 内置 cost tracking + spend 报表 |
| 格式转换 | OpenAI + Anthropic | 100+ provider 统一格式 |
| Fallback | 手动配置备用渠道 | 自动 fallback + 冷却重试 |
| 部署复杂度 | PG + Redis + New API | PG + LiteLLM (更轻) |
| 社区 | 中文活跃 | 英文为主 |
| 适用场景 | 需要完整运营后台的 API 分销/企业网关 | 已有用户体系,只需统一模型接入层 |