Skip to content

Commit 2f8164e

Browse files
committed
update
1 parent 6e75872 commit 2f8164e

File tree

4 files changed

+141
-187
lines changed

4 files changed

+141
-187
lines changed

README.md

Lines changed: 67 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
[English](README.md) | [中文简体](README_CN.md)
44

5-
An enterprise-grade API key management and rotation service, providing intelligent key pool management, automatic failover, and load balancing capabilities.
5+
A lightweight API key management and rotation service designed to provide a simple and efficient solution. It helps developers easily manage API keys through intelligent key pool management, automatic failover, and load balancing. The project also offers enterprise-level deployment options to suit different use cases.
66

77
## ✨ Key Features
88

@@ -90,89 +90,43 @@ docker-compose -f docker-compose.enterprise.yml up -d
9090

9191
### 📋 Environment Variables
9292

93-
#### Database Configuration
94-
```bash
95-
# SQLite (Lightweight - Default)
96-
DATABASE_PATH=/app/data/api_key_rotator.db
97-
98-
# MySQL (Enterprise)
99-
DB_HOST=localhost
100-
DB_USER=appdb
101-
DB_PASSWORD=your_strong_password
102-
DB_NAME=api_key_rotator
103-
DB_PORT=3306
104-
105-
# Or use connection string
106-
DATABASE_URL=mysql://user:password@tcp(host:port)/database?charset=utf8mb4&parseTime=True&loc=Local
107-
```
108-
109-
#### Cache Configuration
110-
```bash
111-
# Memory Cache (Lightweight - Default)
112-
# No additional configuration needed
113-
114-
# Redis (Enterprise)
115-
REDIS_HOST=localhost
116-
REDIS_PORT=6379
117-
REDIS_PASSWORD=your_password
118-
REDIS_URL=redis://localhost:6379/0
119-
```
120-
121-
#### Application Configuration
122-
```bash
123-
# Server
124-
BACKEND_PORT=8000
125-
LOG_LEVEL=info
126-
127-
# Authentication
128-
ADMIN_USERNAME=admin
129-
ADMIN_PASSWORD=your_admin_password_here
130-
JWT_SECRET=your_very_secret_and_random_jwt_key
131-
132-
# Proxy
133-
GLOBAL_PROXY_KEYS=your_secure_global_proxy_key
134-
PROXY_TIMEOUT=30
135-
PROXY_PUBLIC_BASE_URL=http://localhost:8000
136-
137-
# Database reset option
138-
RESET_DB_TABLES=false
139-
```
93+
| Variable | Description | Default | Example |
94+
|---|---|---|---|
95+
| **General** | | | |
96+
| `BACKEND_PORT` | Port for the backend service. | `8000` | `8000` |
97+
| `LOG_LEVEL` | Logging level. | `info` | `debug` |
98+
| `ADMIN_USERNAME` | Initial admin username. | `admin` | `admin` |
99+
| `ADMIN_PASSWORD` | Initial admin password. | `your_admin_password` | `mysecretpassword` |
100+
| `JWT_SECRET` | Secret key for JWT tokens. | `your_very_secret...` | `a_long_random_string` |
101+
| `GLOBAL_PROXY_KEYS` | Global proxy keys, comma-separated. | (empty) | `key1,key2` |
102+
| `PROXY_TIMEOUT` | Proxy request timeout in seconds. | `30` | `60` |
103+
| `PROXY_PUBLIC_BASE_URL` | Public access URL for the service. | `http://localhost:8000` | `https://your.domain.com` |
104+
| **Database** | | | |
105+
| `DB_TYPE` | Database type. | `sqlite` | `mysql` |
106+
| `DATABASE_PATH` | Path for SQLite database file. | `/app/data/rotator.db` | |
107+
| `DB_HOST` | MySQL host. | | `localhost` |
108+
| `DB_USER` | MySQL username. | | `dbuser` |
109+
| `DB_PASSWORD` | MySQL password. | | `dbpass` |
110+
| `DB_NAME` | MySQL database name. | | `rotator_db` |
111+
| `DB_PORT` | MySQL port. | | `3306` |
112+
| `DATABASE_URL` | Database connection string (priority). | | `mysql://...` |
113+
| **Cache** | | | |
114+
| `CACHE_TYPE` | Cache type. | `memory` | `redis` |
115+
| `REDIS_HOST` | Redis host. | | `localhost` |
116+
| `REDIS_PORT` | Redis port. | | `6379` |
117+
| `REDIS_PASSWORD` | Redis password. | | (empty) |
118+
| `REDIS_URL` | Redis connection string (priority). | | `redis://...` |
140119

141120
### 🏗️ Project Structure
142121

143-
```
144-
api-key-rotator/
145-
├── docker-compose.yml # Lightweight deployment
146-
├── docker-compose.enterprise.yml # Enterprise deployment
147-
├── Dockerfile # Default build (lightweight)
148-
├── Dockerfile.enterprise # Enterprise build
149-
├── README.md # Project documentation
150-
└── backend/ # Go backend service
151-
├── main.go # Application entry point
152-
├── go.mod # Go module definition
153-
└── internal/ # Internal packages
154-
├── config/ # Configuration management
155-
│ ├── config.go # Configuration loading
156-
│ └── factory.go # Infrastructure factory
157-
├── infrastructure/ # Infrastructure layer
158-
│ ├── database/
159-
│ │ ├── interface.go # Database repository interface
160-
│ │ ├── sqlite/ # SQLite implementation
161-
│ │ └── mysql/ # MySQL implementation
162-
│ └── cache/
163-
│ ├── interface.go # Cache interface
164-
│ ├── memory/ # Memory cache implementation
165-
│ └── redis/ # Redis implementation
166-
├── handlers/ # HTTP handlers
167-
├── models/ # Data models
168-
├── dto/ # Data transfer objects
169-
├── router/ # Route configuration
170-
└── logger/ # Logger configuration
171-
└── frontend/ # Vue.js frontend
172-
├── src/ # Source code
173-
├── package.json # Dependencies
174-
└── Dockerfile # Frontend build
175-
```
122+
The project is divided into two main parts: `backend` (a core API service written in Go) and `frontend` (a management interface built with Vue.js). Each part has its own `README.md` file with a more detailed structure description.
123+
124+
- `backend/`: The backend service responsible for API proxying, key management, and authentication.
125+
- `frontend/`: The frontend application that provides a user-friendly web interface for managing proxy configurations and keys.
126+
- `Dockerfile`: Used to build the Docker image for the lightweight version.
127+
- `Dockerfile.enterprise`: Used to build the Docker image for the enterprise version.
128+
- `docker-compose.yml`: For quick deployment of the lightweight version.
129+
- `docker-compose.enterprise.yml`: For quick deployment of the enterprise version.
176130

177131
### 🛠️ Tech Stack
178132

@@ -183,18 +137,39 @@ api-key-rotator/
183137
- **Containerization**: Docker + Docker Compose
184138
- **Architecture**: Interface Abstraction + Adapter Pattern
185139

186-
### 🌐 API Endpoints
140+
### 📖 Usage Example
141+
142+
Let's take `OpenRouter` as an example. You can set it up as follows:
143+
144+
1. Create a new proxy configuration in the management interface.
145+
2. **Service Slug**: Enter `openai-openrouter` (customizable).
146+
3. **API Format**: Select `OpenAI Compatible`.
147+
4. **Target Base URL**: Enter `https://openrouter.ai/api/v1`.
148+
5. Add your `OpenRouter` API keys to the key pool for this configuration.
149+
150+
Once configured, you can use it in any OpenAI-compatible client (e.g., `Cherry Studio`). Set the client's `Base URL` or `API Endpoint` to:
187151

188-
After starting the service, you can access the following APIs:
152+
```
153+
${PROXY_PUBLIC_BASE_URL}/llm/openai-openrouter
154+
```
155+
156+
And fill the `API Key` field with the global proxy key you set in the `GLOBAL_PROXY_KEYS` environment variable.
189157

190-
- **Root Path**: `http://localhost:8000/` - Service status information
191-
- **Admin API**: `http://localhost:8000/admin/*` - Backend management interface
192-
- `GET /admin/app-config` - Get application configuration
193-
- `POST /admin/login` - User login
194-
- `GET/POST/PUT/DELETE /admin/proxy-configs` - Proxy configuration management
195-
- `GET/POST/DELETE /admin/proxy-configs/:id/keys` - API key management
196-
- `PATCH /admin/keys/:keyID` - Key status management
197-
- **Frontend Management Interface**: `http://localhost:8000/` - Vue3 admin management interface
158+
- `${PROXY_PUBLIC_BASE_URL}` is the public access address you configure for the service (e.g., `http://localhost:8000`).
159+
- The `openai-openrouter` in `/llm/openai-openrouter` corresponds to the **Service Slug** you set.
160+
161+
You can also test it directly with `curl`:
162+
```bash
163+
# Call the proxy endpoint using curl
164+
curl -X POST ${PROXY_PUBLIC_BASE_URL}/llm/openai-openrouter/v1/chat/completions \
165+
-H "Authorization: Bearer ${GLOBAL_PROXY_KEYS}" \
166+
-H "Content-Type: application/json" \
167+
-d '{
168+
"model": "google/gemini-flash-1.5",
169+
"messages": [{"role": "user", "content": "Hello!"}],
170+
"stream": false
171+
}'
172+
```
198173

199174
### 🐳 Deployment Options
200175

@@ -251,4 +226,4 @@ docker run --env-file .env api-key-rotator:latest
251226

252227
### 📄 License
253228

254-
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
229+
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.

README_CN.md

Lines changed: 67 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
[English](README.md) | [中文简体](README_CN.md)
44

5-
一个企业级的API密钥管理和轮换服务,提供智能的密钥池管理、自动故障转移和负载均衡功能。
5+
一个轻量级的API密钥管理和轮换服务,旨在提供一个简单、高效的解决方案。它通过智能的密钥池管理、自动故障转移和负载均衡功能,帮助开发者轻松管理API密钥。项目同时提供企业级的部署选项,以满足不同的使用场景
66

77
## ✨ 主要功能
88

@@ -90,89 +90,43 @@ docker-compose -f docker-compose.enterprise.yml up -d
9090

9191
### 📋 环境变量
9292

93-
#### 数据库配置
94-
```bash
95-
# SQLite(轻量级 - 默认)
96-
DATABASE_PATH=/app/data/api_key_rotator.db
97-
98-
# MySQL(企业级)
99-
DB_HOST=localhost
100-
DB_USER=appdb
101-
DB_PASSWORD=your_strong_password
102-
DB_NAME=api_key_rotator
103-
DB_PORT=3306
104-
105-
# 或使用连接字符串
106-
DATABASE_URL=mysql://user:password@tcp(host:port)/database?charset=utf8mb4&parseTime=True&loc=Local
107-
```
108-
109-
#### 缓存配置
110-
```bash
111-
# 内存缓存(轻量级 - 默认)
112-
# 无需额外配置
113-
114-
# Redis(企业级)
115-
REDIS_HOST=localhost
116-
REDIS_PORT=6379
117-
REDIS_PASSWORD=your_password
118-
REDIS_URL=redis://localhost:6379/0
119-
```
120-
121-
#### 应用配置
122-
```bash
123-
# 服务器
124-
BACKEND_PORT=8000
125-
LOG_LEVEL=info
126-
127-
# 认证
128-
ADMIN_USERNAME=admin
129-
ADMIN_PASSWORD=your_admin_password_here
130-
JWT_SECRET=your_very_secret_and_random_jwt_key
131-
132-
# 代理
133-
GLOBAL_PROXY_KEYS=your_secure_global_proxy_key
134-
PROXY_TIMEOUT=30
135-
PROXY_PUBLIC_BASE_URL=http://localhost:8000
136-
137-
# 数据库重置选项
138-
RESET_DB_TABLES=false
139-
```
93+
| 变量名 | 描述 | 默认值 | 示例 |
94+
|---|---|---|---|
95+
| **通用** | | | |
96+
| `BACKEND_PORT` | 后端服务监听的端口。 | `8000` | `8000` |
97+
| `LOG_LEVEL` | 日志级别。 | `info` | `debug` |
98+
| `ADMIN_USERNAME` | 管理员初始用户名。 | `admin` | `admin` |
99+
| `ADMIN_PASSWORD` | 管理员初始密码。 | `your_admin_password` | `mysecretpassword` |
100+
| `JWT_SECRET` | 用于生成JWT令牌的密钥。 | `your_very_secret...` | `a_long_random_string` |
101+
| `GLOBAL_PROXY_KEYS` | 全局代理密钥,用逗号分隔。 | (空) | `key1,key2` |
102+
| `PROXY_TIMEOUT` | 代理请求的超时时间(秒)。 | `30` | `60` |
103+
| `PROXY_PUBLIC_BASE_URL` | 服务的公共访问URL。 | `http://localhost:8000` | `https://your.domain.com` |
104+
| **数据库** | | | |
105+
| `DB_TYPE` | 数据库类型。 | `sqlite` | `mysql` |
106+
| `DATABASE_PATH` | SQLite数据库文件路径。 | `/app/data/rotator.db` | |
107+
| `DB_HOST` | MySQL主机。 | | `localhost` |
108+
| `DB_USER` | MySQL用户名。 | | `dbuser` |
109+
| `DB_PASSWORD` | MySQL密码。 | | `dbpass` |
110+
| `DB_NAME` | MySQL数据库名。 | | `rotator_db` |
111+
| `DB_PORT` | MySQL端口。 | | `3306` |
112+
| `DATABASE_URL` | 数据库连接字符串 (优先)。 | | `mysql://...` |
113+
| **缓存** | | | |
114+
| `CACHE_TYPE` | 缓存类型。 | `memory` | `redis` |
115+
| `REDIS_HOST` | Redis主机。 | | `localhost` |
116+
| `REDIS_PORT` | Redis端口。 | | `6379` |
117+
| `REDIS_PASSWORD` | Redis密码。 | | (空) |
118+
| `REDIS_URL` | Redis连接字符串 (优先)。 | | `redis://...` |
140119

141120
### 🏗️ 项目结构
142121

143-
```
144-
api-key-rotator/
145-
├── docker-compose.yml # 轻量级部署
146-
├── docker-compose.enterprise.yml # 企业级部署
147-
├── Dockerfile # 默认构建(轻量级)
148-
├── Dockerfile.enterprise # 企业级构建
149-
├── README.md # 项目文档
150-
└── backend/ # Go后端服务
151-
├── main.go # 应用入口点
152-
├── go.mod # Go模块定义
153-
└── internal/ # 内部包
154-
├── config/ # 配置管理
155-
│ ├── config.go # 配置加载
156-
│ └── factory.go # 基础设施工厂
157-
├── infrastructure/ # 基础设施层
158-
│ ├── database/
159-
│ │ ├── interface.go # 数据库仓库接口
160-
│ │ ├── sqlite/ # SQLite实现
161-
│ │ └── mysql/ # MySQL实现
162-
│ └── cache/
163-
│ ├── interface.go # 缓存接口
164-
│ ├── memory/ # 内存缓存实现
165-
│ └── redis/ # Redis实现
166-
├── handlers/ # HTTP处理器
167-
├── models/ # 数据模型
168-
├── dto/ # 数据传输对象
169-
├── router/ # 路由配置
170-
└── logger/ # 日志配置
171-
└── frontend/ # Vue.js前端
172-
├── src/ # 源代码
173-
├── package.json # 依赖
174-
└── Dockerfile # 前端构建
175-
```
122+
项目分为两大部分:`backend`(Go语言实现的核心API服务)和 `frontend`(Vue.js实现的管理界面)。每个部分都有其独立的`README.md`文件,其中包含更详细的结构说明。
123+
124+
- `backend/`: 后端服务,负责API代理、密钥管理和认证。
125+
- `frontend/`: 前端应用,提供一个用户友好的Web界面来管理代理配置和密钥。
126+
- `Dockerfile`: 用于构建轻量级版本的Docker镜像。
127+
- `Dockerfile.enterprise`: 用于构建企业级版本的Docker镜像。
128+
- `docker-compose.yml`: 用于快速部署轻量级版本。
129+
- `docker-compose.enterprise.yml`: 用于快速部署企业级版本。
176130

177131
### 🛠️ 技术栈
178132

@@ -183,18 +137,39 @@ api-key-rotator/
183137
- **容器化**: Docker + Docker Compose
184138
- **架构**: 接口抽象 + 适配器模式
185139

186-
### 🌐 API端点
140+
### 📖 使用示例
141+
142+
以配置 `OpenRouter` 为例,您可以进行如下设置:
143+
144+
1. 在管理界面创建一个新的代理配置。
145+
2. **服务标识 (Slug)**: 填入 `openai-openrouter` (可自定义)。
146+
3. **API 格式**: 选择 `OpenAI Compatible`
147+
4. **目标 Base URL**: 填入 `https://openrouter.ai/api/v1`
148+
5. 添加您的 `OpenRouter` API 密钥到此配置的密钥池中。
149+
150+
配置完成后,您就可以在任何兼容OpenAI的客户端(例如 `Cherry Studio`)中使用了。将客户端的 `Base URL``API Endpoint` 设置为:
187151

188-
启动服务后,可以访问以下API:
152+
```
153+
${PROXY_PUBLIC_BASE_URL}/llm/openai-openrouter
154+
```
155+
156+
并将 `API 密钥` 字段填写为您在环境变量 `GLOBAL_PROXY_KEYS` 中设置的全局代理密钥。
189157

190-
- **根路径**: `http://localhost:8000/` - 服务状态信息
191-
- **管理API**: `http://localhost:8000/admin/*` - 后台管理接口
192-
- `GET /admin/app-config` - 获取应用配置
193-
- `POST /admin/login` - 用户登录
194-
- `GET/POST/PUT/DELETE /admin/proxy-configs` - 代理配置管理
195-
- `GET/POST/DELETE /admin/proxy-configs/:id/keys` - API密钥管理
196-
- `PATCH /admin/keys/:keyID` - 密钥状态管理
197-
- **前端管理界面**: `http://localhost:8000/` - Vue3后台管理界面
158+
- `${PROXY_PUBLIC_BASE_URL}` 是您为服务配置的公共访问地址 (例如 `http://localhost:8000`)。
159+
- `/llm/openai-openrouter` 中的 `openai-openrouter` 对应您设置的 **服务标识 (Slug)**
160+
161+
您也可以直接使用 `curl` 进行测试:
162+
```bash
163+
# 使用 curl 调用代理接口
164+
curl -X POST ${PROXY_PUBLIC_BASE_URL}/llm/openai-openrouter/v1/chat/completions \
165+
-H "Authorization: Bearer ${GLOBAL_PROXY_KEYS}" \
166+
-H "Content-Type: application/json" \
167+
-d '{
168+
"model": "google/gemini-flash-1.5",
169+
"messages": [{"role": "user", "content": "Hello!"}],
170+
"stream": false
171+
}'
172+
```
198173

199174
### 🐳 部署选项
200175

@@ -252,4 +227,4 @@ docker run --env-file .env api-key-rotator:latest
252227

253228
### 📄 许可证
254229

255-
本项目采用 MIT 许可证 - 详情请参阅 [LICENSE](LICENSE) 文件。
230+
本项目采用 MIT 许可证 - 详情请参阅 [LICENSE](LICENSE) 文件。

frontend/src/locales/en.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,9 @@
7373
"targetBaseUrl": "Please enter a target Base URL",
7474
"keyLocation": "Please select a key location",
7575
"keyName": "Please enter a key name"
76-
}
76+
},
77+
"cancel": "Cancel",
78+
"confirm": "Confirm"
7779
},
7880
"messages": {
7981
"loadFailed": "Failed to load configuration list",

0 commit comments

Comments
 (0)