# llm-gateway **Repository Path**: wrxfxdd/llm-gateway ## Basic Information - **Project Name**: llm-gateway - **Description**: No description available - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2026-06-13 - **Last Updated**: 2026-06-14 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # LLM Gateway 一个轻量自研 LLM Gateway。第一版只接 DeepSeek,但代码结构保留多 provider、多 model 的扩展边界。 ## MVP - `POST /v1/chat/completions` - OpenAI-compatible request / response - DeepSeek provider - API key 鉴权 - 余额检查和扣费 - token usage 记录 - Redis RPM 限流 - 请求日志 ## Local Development ```bash npm install copy .env.example .env npm run db:generate npm run db:push npm run db:seed npm run dev ``` 数据库和 Redis 需要本地可用。也可以先用生产或托管 MySQL / Redis,把连接写入 `.env`。 添加 DeepSeek 上游 key: ```bash npm run channel:add -- --provider deepseek --name main --api-key sk-your-deepseek-key ``` 上游 key 会用 `PROVIDER_KEY_ENCRYPTION_SECRET` 加密后写入 `provider_channels` 表。 创建平台用户 API key: ```bash npm run apikey:create -- --email user@example.com --name default --balance 10 --rpm-limit 60 ``` 返回的 `apiKey` 只显示一次。调用 Gateway 时使用: ```bash curl http://localhost:3000/v1/chat/completions \ -H "Authorization: Bearer sk-lgw-..." \ -H "Content-Type: application/json" \ -d '{"model":"deepseek-chat","messages":[{"role":"user","content":"Hello"}]}' ``` Streaming requests are supported with `"stream": true`. The gateway asks upstream for final usage and only charges when reliable usage is returned. 查看最近请求和 usage: ```bash npm run usage:list ``` 查看余额和交易流水: ```bash npm run balance:list ``` 人工充值: ```bash npm run balance:recharge -- --email user@example.com --amount 10 --currency USD --description "Manual recharge" ``` 调整平台 API key 的 RPM: ```bash npm run apikey:limit -- --key-prefix sk-lgw-xxxxxxx --rpm-limit 60 ``` 禁用或启用平台 API key: ```bash npm run apikey:status -- --key-prefix sk-lgw-xxxxxxx --status disabled npm run apikey:status -- --key-prefix sk-lgw-xxxxxxx --status active ``` 禁用或启用上游 channel: ```bash npm run channel:status -- --provider deepseek --name main --status disabled npm run channel:status -- --provider deepseek --name main --status active ``` ## User Console 面向终端用户的自助界面,支持邮箱注册 / 登录、查看余额和用量、自助创建和禁用 API key。 ```bash npm run user:dev ``` 默认监听 `USER_CONSOLE_PORT`(默认 `3200`),打开 `http://localhost:3200`。 - 注册:填写邮箱后点击「发送验证码」。开发环境不发真实邮件,验证码会打印到 user-console 日志里的 `[dev-email-code]`。输入验证码和密码(至少 8 位)即可注册并自动登录。 - 登录:使用已注册的邮箱和密码。 - 登录后可创建 API key(明文只显示一次)、禁用 key,并查看最近请求和交易流水。 新注册用户余额为 0,需要管理员或 `balance:recharge` 充值后才能调用 Gateway。 ## Admin Console 平台运营后台,使用 `ADMIN_PASSWORD` 登录,可管理用户 API key、充值、调整限流、增删上游 channel。 ```bash npm run console:dev ``` 默认监听 `CONSOLE_PORT`(默认 `3100`),打开 `http://localhost:3100`。 ## Structure ```text apps/gateway API service apps/console Admin console (operator dashboard) apps/user-console User self-service console (signup / login / dashboard) packages/db Prisma schema and database client packages/shared Shared types and provider contracts ``` 详细设计见 [MVP_DESIGN.md](./MVP_DESIGN.md)。