Universal API key and environment variable cycler. Seamlessly cycle through multiple API credential sets for OpenAI, Gemini, Azure, Anthropic, and any other service for locally-stored environment variables (e.g. in a .env file). Features interactive installers, cross-platform compatibility, and intelligent configuration validation. CURRENTLY IN ALPHA - PENDING MORE CROSS-PLATFORM TESTING AND USER REVIEWS
bash <(curl -s https://raw.githubusercontent.com/h0tp-ftw/api-key-cycler/main/install.sh)Invoke-WebRequest -Uri "https://raw.githubusercontent.com/h0tp-ftw/api-key-cycler/main/install.ps1" -OutFile install.ps1; .\install.ps1- 🔄 Universal Key Cycling: Works with any API service (OpenAI, Gemini, Azure, Anthropic, etc.)
- 🎯 Multiple Cycling Modes: Sequential, random, or jump to specific sets
- 🛠️ Interactive Installers: Guided setup for both Unix/Linux and Windows
- 📁 Flexible File Support: Works with any
.env-style configuration file - 🖥️ Cross-Platform: Linux, macOS via Python script, Windows via bat script
- ⚙️ Zero Dependencies: Uses only Python standard library
- Installation Options
- Configuration
- Usage
- Supported File Format
- Example Scenarios
- Platform Compatibility
- Troubleshooting
- Contributing
- License
- Author
- Responsible Usage Notice
| Method | Platform | Command |
|---|---|---|
| Interactive Bash | Linux/Mac/WSL | bash <(curl -s https://raw.githubusercontent.com/h0tp-ftw/api-key-cycler/main/install.sh) |
| Interactive PowerShell | Windows | Invoke-WebRequest -Uri https://raw.githubusercontent.com/h0tp-ftw/api-key-cycler/main/install.ps1 -OutFile install.ps1; .\install.ps1 |
| Manual Download | Any | Download cycle_keys.py or cycle_keys.bat directly and modify it |
- 📁 Directory Setup: Choose installation location
- 🔧 Parameter Configuration: Define your API key groups
- 📄 File Path Setup: Set default .env file location
- 🔍 Format Validation: Check existing .env files and provide guidance
- 🎯 Mode Selection: Choose default cycling behavior (sequential/random)
- 📄 Template Generation: Create sample .env files if needed
During installation, configure your parameter groups. Examples:
GEMINI_API_KEY,VERTEXAI_PROJECT
GEMINI_API_KEY,VERTEXAI_PROJECT|OPENAI_KEY,OPENAI_PROJECT,OPENAI_LOCATION
OPENAI_KEY,OPENAI_PROJECT,OPENAI_LOCATION|AZURE_KEY,AZURE_ENDPOINT,AZURE_REGION|ANTHROPIC_API_KEY
| Argument | Short | Description |
|---|---|---|
--file PATH |
-f |
Path to .env file (default: .env in same directory as script) |
--random |
-r |
Cycle to random set (excludes current set) |
--jump N |
-j |
Jump directly to set number N (1-based) |
--show |
-s |
Display current configuration without changes |
--list |
-l |
List all available sets for each group |
--help |
-h |
Show help message and usage examples |
# Basic cycling (sequential)
python cycle_keys.py
# Random cycling
python cycle_keys.py --random
# Jump to specific set
python cycle_keys.py --jump 3
# Use custom file
python cycle_keys.py --file production.env --random
# Show current configuration
python cycle_keys.py --show
# List all available sets
python cycle_keys.py --listAfter installation, Windows users get additional convenience:
# Using the batch launcher (no need to type "python")
cycle_keys --show
cycle_keys --random
cycle_keys --jump 2Create your .env file with this structure:
# Group 1: OpenAI Configuration
# Set 1 (currently active)
OPENAI_KEY=sk-proj-abc123...
OPENAI_PROJECT=project-alpha
OPENAI_LOCATION=us-east-1
# Set 2 (inactive)
# OPENAI_KEY=sk-proj-def456...
# OPENAI_PROJECT=project-beta
# OPENAI_LOCATION=eu-west-1
# Set 3 (inactive)
# OPENAI_KEY=sk-proj-ghi789...
# OPENAI_PROJECT=project-gamma
# OPENAI_LOCATION=asia-pacific-1
# Group 2: Database URLs
DATABASE_URL=postgres://prod-server/db1
# DATABASE_URL=postgres://staging-server/db1
# DATABASE_URL=postgres://dev-server/db1
# Other configuration (not managed by cycle_keys)
PORT=3000
DEBUG=false- ✅ Active sets: Uncommented lines
- ✅ Inactive sets: Commented with
# - ✅ Logical grouping: Parameters at same position form a set
- ✅ Consistent ordering: Maintain same order across all parameter groups
# When your API key isn't working and you want to cycle to the next
python cycle_keys.py # Development environment
python cycle_keys.py dev.env --jump 2
# Production environment (check first, then switch)
python cycle_keys.py prod.env --show
python cycle_keys.py prod.env --random#!/bin/bash
# Simple failover script
if ! curl -f "https://api.example.com/health"; then
echo "API down, cycling keys..."
python cycle_keys.py --random
systemctl restart api-service
fi@echo off
REM Windows batch script for key cycling
cycle_keys --random
if %errorlevel% equ 0 (
echo Key cycling successful
net restart "My API Service"
) else (
echo Key cycling failed
)| Platform | Installer | Execution Method |
|---|---|---|
| Linux | install.sh |
python3 cycle_keys.py |
| macOS | install.sh |
python3 cycle_keys.py |
| Windows PowerShell | install.ps1 |
python cycle_keys.py or cycle_keys.bat |
| Windows WSL | install.sh |
python3 cycle_keys.py |
| Git Bash | install.sh |
python cycle_keys.py |
| Windows Terminal | install.ps1 |
python cycle_keys.py or cycle_keys.bat |
- Direct Python:
python cycle_keys.py [args] - Windows Batch:
cycle_keys [args](Windows only) - Shebang:
./cycle_keys.py [args](Unix-like systems)
Q: "Python not found" error on Windows
# Try these commands in order:
python --version
python3 --version
py --version
# If none work, install Python from python.orgQ: ".env file format issues"
- Run
python cycle_keys.py --listto see current format - Use installer to generate template files
- Ensure all parameter groups have same number of entries
Q: "Permission denied" on Unix systems
chmod +x cycle_keys.py
# Or use: python3 cycle_keys.pyQ: "Script not found" after installation
# Check installation directory
which cycle_keys.py
# Add to PATH or use full path
export PATH=$PATH:/path/to/installation/directory- Run
python cycle_keys.py --helpfor usage information - Re-run installer to reconfigure settings
- Check the installation directory for all files
- Verify .env file format with
--listcommand
Contributions are welcome! Here's how you can help:
# Clone the repository
git clone https://github.com/h0tp-ftw/api-key-cycler.git
cd api-key-cycler
# Test the script
python cycle_keys.py --help
# Test installers
bash install.sh # Unix/Linux
# or
PowerShell install.ps1 # Windows- 🍴 Fork the repository
- 🌿 Create a feature branch (
git checkout -b feature/amazing-feature) - 🧪 Test your changes on multiple platforms if possible
- 📝 Update documentation if needed
- ✅ Commit your changes (
git commit -m 'Add amazing feature') - 🚀 Push to your branch (
git push origin feature/amazing-feature) - 🎯 Open a Pull Request
| Code | Description |
|---|---|
0 |
Success - operation completed successfully |
1 |
Error - configuration issue, file not found, invalid format, etc. |
- 🐍 Python 3.7+ compatible
- 📦 Zero external dependencies required
- ⚡ < 500 lines of clean, documented code
- 🧪 Cross-platform tested across multiple environments
- 📚 Comprehensive documentation with real-world examples
- python-dotenv - Load environment variables from .env files
- direnv - Environment variable management per directory
- dotenv-vault - Encrypted .env file management
This project is licensed under the MIT License - see the LICENSE file for details.
Created by @h0tp-ftw, powered by Claude 4.0 Sonnet
If this tool helped you manage your API keys more efficiently, consider giving it a ⭐!
API Key Cycler is intended for responsible API key management only.
Do not use this tool to evade service rate limits, quotas, account restrictions, or engage in unauthorized, abusive, or illegal activities.
Always follow the terms of service and usage policies of your API providers.
Use API Key Cycler for security best practices—such as safe key rotation, disaster recovery, and organizational credential management—not for circumventing provider limits or abusing access.
If you have questions about permitted usage, consult the relevant API documentation or service agreement.
(Responsible API key usage helps protect your account, your service, and the wider community.)