A simple OpenAI API key management platform for efficiently managing and optimizing API key pools, implementing proxy requests and key rotation.
- Bulk Key Addition: Add multiple OpenAI API keys at once
- Key Status Management: Maintain valid/invalid status of keys
- Automatic Validation: Automatically validate the validity of keys
- Batch Reset: Reset all invalid keys to valid status with one click
- Intelligent Proxy: Automatically route requests to valid API keys
- Load Balancing: Evenly distribute requests to optimize key usage
- Real-time Statistics: Display call statistics for the last 1 minute, 1 hour, 24 hours, and total
- Key Usage Tracking: Record the number of uses and last used time for each key
- Key Pool Status: Display valid/invalid key count statistics
- Responsive Design: Adapt to different device screen sizes
- Paginated Browsing: Efficiently browse and manage large numbers of keys
- Intuitive Operation: Clear and straightforward operation interface
- Python 3.8+
- FastAPI
- SQLAlchemy
- Other dependencies (see requirements.txt)
-
Clone the repository
git clone https://github.com/Inblac/gpt-proxy.git cd gpt-proxy -
Create a virtual environment and install dependencies
python -m venv venv source venv/bin/activate # Windows: venv\Scripts\activate pip install -r requirements.txt
-
Create a data directory and configure config.ini
mkdir data cp config.ini.example data/config.ini # Edit data/config.ini as needed -
Initialize the database (will be created as ./data/gpt_proxy.db)
python -m gpt_proxy.database.init_db # This will create data/gpt_proxy.db if it does not exist -
Start the service
uvicorn gpt_proxy.main:app --host 0.0.0.0 --port 8000
- Both
config.iniandgpt_proxy.dbmust be placed in the./datadirectory. - When using Docker or docker-compose, mount the host's
./datadirectory to the container's/datadirectory:
docker-compose.yml example:
version: '3.8'
services:
gpt-proxy:
build: .
ports:
- "8000:8000"
volumes:
- ./data:/data
restart: unless-stoppedThis ensures all configuration and data are persistent and easy to manage.
- Visit the system homepage
http://localhost:8000/ - Log in using the admin API Key
- In the admin interface, find the "Add New OpenAI API Key" section
- Enter one or more API keys (one per line)
- Click the "Add Keys" button
- Click "Set Invalid" or "Set Valid" in the key list to toggle key status
- Use the "Revalidate All Invalid Keys" button to verify key validity
- Use the "Reset All Invalid Keys to Valid Status" feature to batch restore keys
- The dashboard displays call statistics and key pool status
- Statistics automatically refresh every 30 seconds
POST /v1/*- Proxy all requests to the OpenAI API
POST /token- Admin authenticationGET /api/stats- Get statistics dataGET /api/keys/paginated- Get paginated key listPOST /api/keys/bulk- Bulk add keysDELETE /api/keys/{key_id}- Delete specified keyPUT /api/keys/{key_id}/status- Update key statusPOST /api/validate_keys- Trigger key validation
- Use a strong password as the admin API Key
- Regularly rotate the admin API Key
- Run the system in a protected network environment
- Avoid exposing the admin interface in public environments
Bug reports and feature requests are welcome. If you want to contribute code, please open an issue to discuss your ideas first, then submit a PR.
GPT-Proxy默认使用SQLite数据库存储API密钥和相关数据。现在也支持使用PostgreSQL作为替代选项。
在data/config.ini文件中,添加或修改[Database]部分来配置数据库:
[Database]
# 数据库类型: sqlite (默认) 或 postgresql
type = sqlite
# 以下配置仅在 type = postgresql 时使用
host = localhost
port = 5432
database = gpt_proxy
user = postgres
password = your_password如果要使用PostgreSQL,需要安装psycopg2库:
pip install psycopg2-binary然后修改配置文件,将type设置为postgresql,并配置正确的连接参数。