Skip to main content
Glama

quota-router

English | 简体中文

Universal quota-aware LLM router, zero-dependency local streaming proxy, and MCP control plane for AI coding harnesses.

Supports Antigravity (agy), Hermes Agent, OpenAI Codex, Claude Code (cc), DSH, OpenCode, and any OpenAI- or Anthropic-compatible client.

Why quota-router?

Developers who juggle multiple AI subscriptions and API plans frequently run into three issues:

  • One plan's short-term rolling window gets rate-limited while another plan's monthly quota sits unused and expires.

  • Switching plans manually breaks flow, risks breaking harness configs, or invalidates a long-context prompt cache mid-session.

  • Heavy cross-protocol gateways frequently drop usage, corrupt reasoning fields, or fail silently with 502s.

quota-router solves this with a dual-plane, zero-dependency architecture:

  • Data plane: Local HTTP/1.1 streaming proxy (/v1/chat/completions, /v1/responses, /v1/messages, /v1/models, /readyz, /_status, /_dashboard) with same-protocol passthrough and pre-first-byte failover.

  • Control plane: Stdio JSON-RPC 2.0 MCP server, CLI, and universal SKILL.md sharing the same SQLite state store and Tiered Pacing engine so closed OAuth/App pools participate in unified scheduling.

Related MCP server: MAGDA-MCP

Key Features

  • Zero mandatory dependencies: Pure Python 3.11+ standard library (tomllib, sqlite3, http.client, ssl). Optional PyYAML extra for .yaml configs.

  • Protocol-preserving passthrough: Routes strictly to upstreams supporting the incoming protocol; relays SSE chunk-by-chunk, preserves usage, and supports opt-in error-code normalization.

  • Tiered Pacing & EWMA burn-rate engine: Group models into task tiers (auto:long, auto:fast, auto:boss, or auto). Candidates are ranked by multi-window pace gap, expiring-plan urgency, EWMA time-to-wall prediction, and peak-hour multipliers.

  • Tiered session stickiness: Sticky tiers (auto:long) pin each conversation to protect prompt cache; burst tiers (auto:fast) balance dynamically per request.

  • Pre-first-byte failover: Automatically fails over on 429 / 5xx / empty stream / connection drop before the first chunk is written; passes through 400/413/422 directly; returns 503 with Retry-After if all pools are exhausted.

  • Three-tier quota sensing: Background Pull probes (CLI/HTTP adapters), local SQLite metering + Retry-After/*-ratelimit-* header feedback (metering), and CLI/MCP calibration for closed pools (manual).

  • Safe harness integration: Zero-invasion qrouter run <harness> launcher + --dry-run/backup/revert persistent integrators for agy, hermes, and codex.

  • Built-in observability: qrouter status / watch, zero-build Web Dashboard at /_dashboard, SQLite telemetry, and redacted JSONL audit logs.

  • Credentials by reference only: Config files never store plaintext API keys—only env, env_file, or command references.

Quickstart

# Install from GitHub or local checkout (Python 3.11+)
uv tool install git+https://github.com/mmqfans/quota-router.git
# or locally: uv tool install -e .

# Initialize starter config and check credentials/probes
qrouter init
qrouter doctor --probe

# Start background proxy and check live status
qrouter start
qrouter status

Open http://localhost:41580/_dashboard in your browser for the live quota dashboard.

Connect Harnesses

# Zero-invasion trial (does not modify any config file)
qrouter run codex --tier long
qrouter run claude --tier fast

# Preview persistent integration (dry-run by default)
qrouter integrate agy
qrouter integrate hermes
qrouter integrate codex

# Apply with automatic backup (revert anytime via `qrouter revert <harness>`)
qrouter integrate codex --apply

CLI Reference

Command

Description

qrouter init

Create starter ~/.config/quota-router/config.toml

qrouter doctor [--probe]

Validate config, credential presence (masked), and probe health

qrouter start / stop

Manage background proxy daemon

qrouter serve

Run proxy in foreground

qrouter status [--refresh] [--json]

Show pool quotas, 5h burn rates, cooldowns, and tier picks

qrouter watch [-n 5]

Live refreshing terminal dashboard

qrouter route <model_or_tier>

Inspect exact pacing scores for a model or auto:<tier>

qrouter calibrate <pool> ...

Calibrate closed/manual pools or mark throttling

qrouter run <harness> [--tier long]

Zero-invasion harness launcher with auto-start

qrouter integrate <harness> [--apply]

Preview or apply harness integration (agy, hermes, codex)

qrouter revert <harness>

Restore original harness config from latest backup

qrouter mcp

Start stdio JSON-RPC 2.0 MCP server

qrouter launchd [--write]

Generate optional macOS LaunchAgent plist

Documentation

Security

  • Binds to loopback (127.0.0.1) by default. Non-loopback hosts refuse to start unless server.auth_token_env is configured.

  • Plaintext API keys are never written to config files, SQLite, JSONL audit logs, /_status, or MCP responses.

License

MIT

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    Related MCP Connectors

    Related MCP Servers

    • F
      license
      Not graded
      quality
      B
      maintenance
      Enables MCP clients to analyze call graphs, run Grover-ranked code searches, generate boundary test cases, get refactoring suggestions, and inspect quantum backends through stdio JSON-RPC tools.
      2
      -
    • A
      license
      Not graded
      quality
      B
      maintenance
      Enables MCP clients to connect to a running MAGDA instance over stdio and access its native composition tools, resources, and resource templates, while providing instance discovery, fixed-instance connection, credential recovery, diagnostics, and compatibility checks.
      MIT
    • A
      license
      B
      quality
      B
      maintenance
      Exposes the six-echelon quality pipeline over stdio JSON-RPC 2.0, enabling MCP clients to manage frozen baselines, HMAC-approved gates, phase role isolation, safe rollback, independent verification, W3C PROV-DM audit chains, and CAPA consolidation.
      10
      1
      MIT
    • A
      license
      Not graded
      quality
      C
      maintenance
      Enables MCP clients to delegate analytics questions, sample-size calculation, knowledge retrieval, and metric listing to a deterministic statistical engine over stdio JSON-RPC.
      MIT