Skip to content

CourseOrchestra/open-router-monitoring

Repository files navigation

OpenRouter API Key Usage Monitor

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.

Features

  • 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

Installation

Docker Usage

You can also run the monitor using Docker for better isolation and easier deployment.

Using Docker Run

  1. Build the Docker image:

    docker build -t openrouter-monitor .
  2. Create a .env file with your API key and desired interval:

    OPENROUTER_API_KEY=your-api-key-here
    CHECK_INTERVAL=2
  3. Run the container using the env file:

    docker run --rm \
      --env-file .env \
      -v $(pwd)/logs:/app/logs \
      openrouter-monitor

    Alternatively, 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

Without Docker Usage

Ensure you have Python 3.6+ installed

Install the required dependency:

pip install requests

Download the openrouter_monitor.py script

Usage Basic Usage

python openrouter_monitor.py

You'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.py

Command 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

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors