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.
0 commit comments