A real-time monitoring tool for tracking your OpenRouter API key usage and credits with a clean, compact console output. It logs to a file only when changes occur, minimizing noise while keeping you informed.
-
Real-time monitoring - Continuously tracks your API key usage
-
Change-only logging - Console updates and file logging only when usage changes
-
Color-coded output - Easily distinguish between increases (red) and decreases (green)
-
Persistent log file - All changes are timestamped and saved
-
Graceful shutdown - Press Ctrl+C to stop and see final statistics
-
Cross-platform - Works on Windows, macOS, and Linux
-
Compact display - All key information in a single line per change
You can also run the monitor using Docker for better isolation and easier deployment.
-
Build the Docker image:
docker build -t openrouter-monitor . -
Create a
.envfile with your API key and desired interval:OPENROUTER_API_KEY=your-api-key-here CHECK_INTERVAL=2
-
Run the container using the env file:
docker run --rm \ --env-file .env \ -v $(pwd)/logs:/app/logs \ openrouter-monitorAlternatively, you can pass environment variables directly:
docker run --rm \ -e OPENROUTER_API_KEY="your-api-key-here" \ -e CHECK_INTERVAL=30 \ -v $(pwd)/logs:/app/logs \ openrouter-monitor
Ensure you have Python 3.6+ installed
Install the required dependency:
pip install requestsDownload the openrouter_monitor.py script
Usage Basic Usage
python openrouter_monitor.pyYou'll be prompted to enter your OpenRouter API key. Alternatively, you can set it as an environment variable:
bash export OPENROUTER_API_KEY="your-api-key-here"
python openrouter_monitor.pyCommand Line Options
python openrouter_monitor.py [--interval SECONDS] [--log-file PATH]Options: -i, --interval SECONDS Check interval in seconds (default: 60) -l, --log-file PATH Log file path (default: openrouter_usage.txt) Examples Monitor every 30 seconds with custom log file:
python openrouter_monitor.py -i 30 -l my_usage.log