Building a Menu Bar App to Monitor LLM API Usage and Rate Limits in Real Time

    Most LLM services enforce usage quotas—rolling time windows or periodic caps—but clients rarely show how much you've consumed or when limits reset. This article walks through building a lightweight macOS menu bar app that tracks API usage in real time, covering credential security, polling with backoff, usage prediction, threshold-based notifications, and cross-architecture builds. It's a practical exercise in desktop observability engineering.

    1. Why Usage Monitoring Matters

    Most mainstream LLM services rely on quota-based or pay-as-you-go models, typically with two types of constraints:

    • Session/time-window quotas: for example, usage limits over a rolling 5-hour window;
    • Periodic quotas: for example, weekly or monthly cumulative caps.

    The typical pain point is that users can’t see “current consumption percentage” or “quota reset time” directly in the client, forcing them to jump back to a settings page and check manually. For heavy users, these frequent, repetitive checks interrupt workflow—and can still lead to hitting a limit mid-task.

    From an engineering perspective, this is fundamentally a resource observability problem—the same category as server monitoring or cost dashboards, except the monitored object is model call quotas instead of infrastructure. The solution pattern is identical: collect metrics periodically → render locally → trigger alerts at thresholds.

    2. Solution Overview

    A typical menu bar usage monitor can be abstracted into four layers:

    1. ┌───────────────┐ ┌─────────────┐ ┌──────────────┐ ┌────────────────┐
    2. │ Credential & │ → │ Data │ → │ State │ → │ Display & │
    3. │ Auth Layer │ │ Collection │ │ Computation │ │ Alerts │
    4. │ (local Cookie)│ │ (polling) │ │ (% / reset) │ │ (menu / notif) │
    5. └───────────────┘ └─────────────┘ └──────────────┘ └────────────────┘

    1. Credentials and Auth: Local-Only Is the Baseline

    Usage data usually comes from a server-side account API, authenticated with session credentials. Two principles should guide the implementation:

    • Store credentials locally only: session cookies should live in system-level secure storage (such as macOS Keychain) or an encrypted local file—never sent anywhere else;
    • Least privilege: only request the credentials needed for usage queries, nothing more.

    2. Data Collection: Timed Polling with Backoff

    The collection layer calls the usage API on a timer. A robust implementation needs to account for:

    1. // Pseudocode: polling scheduler with backoff
    2. let baseInterval: TimeInterval = 300 // normal: 5 minutes
    3. let backoffInterval: TimeInterval = 1800 // backoff to 30 minutes on failure
    4. func scheduleNextFetch(failureCount: Int) {
    5. let interval = failureCount == 0
    6. ? baseInterval
    7. : min(backoffInterval * pow(2, failureCount - 1), 3600)
    8. timer.schedule(after: .now() + interval) {
    9. self.fetchUsage { result in
    10. self.scheduleNextFetch(
    11. failureCount: result.isSuccess ? 0 : failureCount + 1
    12. )
    13. }
    14. }
    15. }

    Key design points:

    • Balancing poll frequency: intervals that are too short waste requests or even trigger rate limiting; too long, and alerts lag behind. Five minutes is a common sweet spot;
    • Network error handling: retry with exponential backoff to avoid a cascade of retries during network instability;
    • Multiple accounts/tiers: if a user has both free and paid quotas, the collection layer should fetch them separately and label them accordingly.

    3. State Computation: Percentage, Trend, and Reset Time

    Once you have raw usage data, three core metrics need to be computed:

    Metric Calculation Purpose
    Remaining percentage 1 - used / limit Direct display in menu bar
    Reset time Window start + window length Planning task pacing
    Consumption rate Difference across recent N samples / time delta Predicting when the limit hits

    The “consumption rate” is the most interesting advanced capability: by averaging consumption speed over a sliding window, you can predict when the quota will be exhausted rather than just alerting after the fact. For example:

    1. # Simple linear extrapolation
    2. def predict_exhaustion(samples, limit):
    3. # samples: [(timestamp, used), ...]
    4. rate = (samples[-1][1] - samples[0][1]) / (samples[-1][0] - samples[0][0])
    5. if rate <= 0:
    6. return None
    7. remaining = limit - samples[-1][1]
    8. return samples[-1][0] + remaining / rate

    4. Display and Alerts: Menu Bar Plus Multi-Level Threshold Notifications

    The menu bar offers the best display real estate on macOS. Implementation tips:

    • Compact text display: menu bar space is limited, so show a compact format like “73%” and expand details on hover or click;
    • Multi-level threshold alerts: trigger system notifications at 25%, 50%, 75%, 90%, and other checkpoints, so users are warned while they can still adjust plans—rather than discovering the cap only after hitting it;
    • Global hotkey: register a global shortcut like Cmd+U so users can open the detail panel without touching the mouse—a meaningful quality-of-life improvement for keyboard-driven developers.

    3. Lightweight and Private: Underrated Engineering Discipline

    Whether a resident utility gets long-term use depends on two often-overlooked dimensions:

    Resource footprint. Users are highly sensitive to the CPU and memory overhead of always-on apps. In practice:

    • Use native system UI frameworks (such as macOS MenuBarExtra) and avoid heavyweight runtimes;
    • Keep the binary in the single-digit-MB range;
    • Sleep between collection intervals—event-driven rather than busy polling.

    Privacy first. Usage data isn’t sensitive per se, but credential security is non-negotiable. Mature privacy design means zero data collection, zero telemetry, locally encrypted credential storage, and being fully open source. Open source not only lets the community audit the code to verify your claims—it’s also the most effective way for any credential-handling resident tool to build trust.

    4. Cross-Architecture Build Considerations

    macOS currently runs on both Apple Silicon and Intel, and releases typically follow one of two strategies:

    1. Universal Binary: a single build containing both arm64 and x86_64—double the size, but simple distribution;
    2. Per-architecture releases: smaller downloads, but users must choose the right one.

    For a lightweight tool in the 5MB range, the cost of a Universal Binary is negligible, making it the friendlier option. At the CI level, one command does the job:

    1. lipo -create build/arm64/app build/x86_64/app -output app_universal

    5. Directions for Extension

    Generalizing the framework above opens up further scenarios:

    • Multi-service aggregated monitoring: show quota status across multiple model services in one place—a personal “quota dashboard”;
    • Cost estimation: combine token consumption with pricing to compute real-time cost;
    • Automated scheduling: when usage approaches a threshold, automatically switch low-priority tasks to a fallback model or defer them;
    • Team scenarios: aggregate usage across team members to help managers with budgeting and quota allocation.

    6. Closing Thoughts

    A small menu bar usage tool ties together a full set of desktop engineering practices: observability, credential security, scheduled tasks, system notifications, and cross-architecture builds. For developers, rather than complaining after being throttled, it’s better to spend a weekend building a monitoring tool that fits your own workflow—it solves a real pain point and doubles as excellent practice for sharpening your systems skills. Of all the design principles, the most important one remains: local-first, privacy-first, lightweight and always-on.