ghuntley/underclass
underclass: an OpenAI-compatible pooling proxy that pins sessions to one account (prompt cache stays warm), cools quota-exhausted subscriptions until their window resets, and fails fast with the earliest Retry-After when the whole pool is dry.
What it solves
Subscription-based AI models have per-account quotas. One account is a ceiling, but many accounts can form a pool. underclass combines multiple ChatGPT/Codex, GitHub Copilot, and Claude Code subscriptions into a single local endpoint that behaves like one well-provisioned provider. It eliminates quota whiplash by rotating exhausted accounts automatically and keeping healthy ones in service, so clients never see account churn. It also avoids cache waste by pinning sessions to the same upstream subscription, keeping prompt caches warm across turns.
How it works
underclass runs as a local proxy that exposes three API surfaces: OpenAI-compatible /v1/responses and /v1/chat/completions, and Anthropic's /v1/messages. Any client that speaks these protocols can point to it without modification. When a request arrives, underclass routes it to a suitable backend based on the requested surface and model, using a flat pool where accounts compete by least in-flight requests.
Accounts are managed through a web UI or CLI. You add subscriptions by authenticating via device flow or paste-back. Each account's quota state is tracked: when a quota limit is hit, the account goes into a cooling period until its window resets (based on upstream retry-after or a default). Sticky sessions make sure requests with a prompt cache key always use the same subscription for 24 hours, surviving restarts and rebinding preferentially to the same backend when an account recovers.
The proxy records every attempt in SQLite with token usage, outcome, and timing. It can redeem banked reset credits for Codex accounts automatically when all are exhausted; for Claude Code it's manual only. If every eligible account is cooling, it fails fast with a 429 and the earliest reset time instead of queuing.
Who it’s for
Developers and power users who have multiple subscriptions to AI coding assistants (ChatGPT/Codex, GitHub Copilot, Claude Code) and want to combine them into one reliable, high-quota endpoint. It's especially useful for heavy users, teams, or anyone who wants to avoid hitting per-account limits while keeping the convenience of standard API calls. The tool is also Nix-friendly and can run as a NixOS service.
Highlights
- No client changes – works with any OpenAI-compatible client or Claude Code by setting the base URL.
- Sticky sessions – requests with a prompt cache key always hit the same subscription, preserving prompt caches.
- Automatic quota rotation – exhausted accounts cool down and rejoin the pool when reset, without manual intervention.
- Fail-fast – if all accounts for a model are cooling, returns 429 with the earliest reset time.
- Two surfaces, one pool – OpenAI and Anthropic APIs are separated, so requests never hit the wrong backend.
- Token accounting – per-attempt usage stored in SQLite, with admin UI and CLI stats for current-month totals and history.
- Stream outcome tracking – logs how each stream ended (completed, failed, truncated, etc.) and capacity/quota events.
- Catalog as data – model lists are configurable and refreshed live from providers; unknown models pass through for forward compatibility.
- Nix/NixOS integration – installable as a package, flake, or NixOS module with a monitor socket.
- Security – secrets never logged; correlation IDs preserved for tracing with preflight.
Related
- Project
- Project
- Project
- Project