Advanced Workflows

Usage Auditing, Quota Tracking & Cost Control

Audit token metrics, cache hit ratios, and savings via magpie quota and the interactive TUI dashboard.

During intensive software development with AI coding agents, transparent visibility into API usage, costs, and account limits is vital. Individual developers want to track daily spending, team leads need to troubleshoot unexpected token consumption, and power users must monitor how close they are to rate limits.

Conventionally, developers are forced to repeatedly log in to separate vendor portals across OpenAI, Anthropic, DeepSeek, and Moonshot to inspect disparate billing dashboards.

Magpie AI normalizes and audits all API requests flowing through its local gateway (127.0.0.1:3425). It provides instant quota audits via magpie quota, interactive terminal charts in magpie tui, and detailed local request logs.


Instant Quota Inspection: magpie quota

Run a single command to inspect active quotas and rate limits across all configured providers and linked accounts:

bash
# Query remaining quota and rate limit status across all providers
magpie quota

Sample output:

text
PROVIDER / ACCOUNT       STATUS     QUOTA REMAINING     RATE LIMIT (RPM/TPM)    WINDOW RESETS
claude-pro-personal      ACTIVE     82% (41 msgs left)  --                      in 2h 14m
deepseek-commercial      ACTIVE     $48.20 / $50.00     60 RPM / 100k TPM       --
kimi-api-key             ACTIVE     ¥126.50             120 RPM                 --
chatgpt-plus-team        ACTIVE     100% (Ready)        --                      Ready

Highlights:

  • Aggregated View: Commercial API balances (USD/CNY) alongside web subscription session metrics (remaining messages and window reset timers) are displayed side by side.
  • Low-Quota Alerts: Accounts below 15% or nearing sliding-window caps are highlighted in yellow for immediate attention.
  • Sub-Second Output: Reads from the local gateway's cached state machine rather than waiting for slow external web scrapers.

Interactive TUI Usage & Cost Dashboard

Launch magpie tui and press Tab to navigate to the 「Usage」 pane:

text
┌─── Magpie AI Usage & Metrics ────────────────────────────────────────────────────────┐
│  TODAY'S TOKENS: 1,428,950    EST. COST: $0.38 (Saved ~$9.40 via DeepSeek & Cache)   │
│  CACHE HIT RATIO: 76.4%       SUCCESS RATE: 99.8%     AVG LATENCY: 340ms             │
├──────────────────────────────────────────────────────────────────────────────────────┤
│  Token Hourly Trend:                                                                 │
│   200k ┤                                 ╭─╮                                         │
│   150k ┤                      ╭──────────╯ │ ╭╮                                      │
│   100k ┤            ╭─────────╯            ╰─╯│                                      │
│    50k ┤    ╭───────╯                         ╰────────                              │
│      0 ┴────┴───────┴─────────┴────────────┴──┴────────                              │
│            09:00   12:00     15:00        18:00     21:00                            │
├──────────────────────────────────────────────────────────────────────────────────────┤
│  Top Active Agents & Models:                                                         │
│  - Claude Code -> deepseek/deepseek-v4-pro : 1,120,400 tokens (84 requests)          │
│  - Codex       -> kimi/kimi-k2.5           :   215,300 tokens (32 requests)          │
│  - OpenCode    -> openai/gpt-4o            :    93,250 tokens (11 requests)          │
└──────────────────────────────────────────────────────────────────────────────────────┘

Essential Observability Metrics:

  1. Total Tokens Consumed: Accurate summation of input tokens, output tokens, cache creation tokens, and cache read tokens.
  2. Cache Hit Ratio: In extended multi-file repository audits, Anthropic Prompt Caching and DeepSeek Context Caching reuse 70%~90% of prompt context. Magpie isolates cache read tokens so you can evaluate real savings.
  3. Estimated Cost Saved: Using built-in official pricing models, Magpie compares your actual spending against hypothetical official Claude 3.5 Sonnet costs to quantify true financial savings.

Full-Fidelity Local Audit Logging

When an AI assistant throws an unexpected error, local logs reveal the exact root cause:

bash
# View the last 20 requests
magpie logs

# Stream real-time log traffic (similar to tail -f)
magpie logs -f

# Inspect the full request/response payload of a failed call
magpie logs show req_abc12345

Log Audit Metadata:

  • Request Metadata: Originating agent (e.g. Claude Code), timestamp, and round-trip latency in milliseconds;
  • Routing Path: The specific upstream provider and model assigned (e.g., routed via group/opus-anywhere down to deepseek/deepseek-v4-pro);
  • Token Breakdown: Granular split between prompt_tokens, completion_tokens, and cache_read_tokens;
  • HTTP Diagnostics: Exact HTTP response codes (200, 429, 502) and upstream error bodies.

Privacy & Data Retention Principles

  • Strictly Local Storage: Audit logs and usage stats reside strictly on your local disk (~/.magpie/data/) and are never dispatched to external servers.
  • Sanitized Logs: When Prompt Masking & Privacy is active, recorded payloads redact credentials and private IP addresses automatically.
  • Lifecycle Retention: Configure retention periods (14 days by default) or wipe logs anytime with magpie logs clear.

FAQ

Q: How accurate is magpie quota for web subscriptions like Claude Pro?

A: Highly accurate. For mounted web subscription accounts, Magpie extracts authentic remaining message quotas and window reset countdowns directly from official sessions, calibrating them against local request counts.

Q: How much money does Prompt Caching actually save?

A: In long-context multi-step coding missions, prompt caching typically reduces input token costs by 70% to 90%. Because project context repeats across turns, vendors like Anthropic and DeepSeek charge roughly 10% of standard pricing for cached input tokens, which Magpie tallies into dollar savings.

Q: Will local request logs eventually consume excessive disk space?

A: No. Magpie uses an efficient embedded datastore and automatically applies a 14-day rolling retention policy. If you wish to purge logs immediately, simply run magpie logs clear.