
Engineering Bottom Line: Running an AI coding loop where Claude (5x) handles architecture, Codex (Pro $200) handles edge-case review, and DeepSeek 1017 executes 80%+ of implementation work at 5x the generation speed burns through a $10 opencode-go weekly quota in roughly one day. To eliminate constant session exits on 429 rate limits, I built and open-sourced **OpenSelect** (MIT License) — a single-process Bun + TypeScript local daemon with 0 runtime npm dependencies (backed by bun:sqlite and covered by 277 automated tests) that exposes a unified Anthropic + OpenAI proxy on :8788 and a live telemetry dashboard on :8789.
- Pre-First-Byte Failover Without Dropping Sessions: Background usage polling every 45 seconds proactively shifts new sessions at a configurable 97% quota threshold, while in-flight requests hitting
429,401,403,5xx, or mid-header stream drops fail over across accounts before the first byte reaches Claude Code or opencode. - Local Anthropic-to-OpenAI Protocol Translation: Pointing
ANTHROPIC_BASE_URL=http://127.0.0.1:8788lets Claude Code drivedeepseek-v4.1-flash,glm-5.1, and 37+ catalog models natively — including[1m]context detection that returns a localprompt is too longsignal at1,048,576tokens to trigger/compactcleanly. - Cross-Provider Fallback Chain: Aggregates
opencode-gopools with Z.ai (GLM), MiniMax, Command Code, Ollama Cloud, and DeepSeek Official (fallbackOnly=true) under an automatedcoding-autorouting ladder andfree-firstzero-cost overflow mode.
Why Single-Account Subscriptions Break Multi-Model Coding Loops
Over the past few months, my daily development workflow settled into a strict three-tier division of labor:
- Leader (Architecture & Final Sign-Off): Claude (5x) handles system design, cross-module decomposition, and final decisions.
- Assister (Co-Review & Edge Cases): Codex (Pro $200) handles boundary checks and targeted review.
- Editor (High-Volume Implementation): DeepSeek 1017 handles over 80% of hands-on code generation because its coding feel and >5x faster generation speed keep iteration tight.
The bottleneck wasn't model quality — it was quota throughput. At peak intensity, I ran 17 concurrent $10 opencode-go subscriptions, burning an entire account's weekly allowance roughly once per day, alongside Z.ai (GLM), MiniMax, Command Code (Kimi), and DeepSeek's pay-as-you-go API.
Because Claude Code (alongside opencode) is my daily terminal entrypoint, two recurring failures broke flow multiple times a day:
- Forced Session Restarts on
429Limits: Whenever an active account hit its 5-hourrollingcap orweeklycap — or when switching to GLM or MiniMax — I had to exit the active Claude Code session, swap configs, and lose conversational momentum. - Brittle Existing Proxies: The 2–3 open-source rotation tools I tested required heavy manual config mapping across providers and offered zero real-time visibility into per-window pressure.
**OpenSelect** collapses quota polling, pre-first-byte failover, protocol translation, and time-of-day route pricing into one local daemon.
opencode / Claude Code (37+ models & multi-provider aliases)
│ baseURL = http://127.0.0.1:8788
▼
OpenSelect Proxy :8788 ┌────────────── Usage Poller (45s parallel poll)
├─ /chat/completions /responses ────► │ https://opencode.ai/inference/go
│ /openai/v1/... │ + direct provider pool (Z.ai/MiniMax/CC/DS/Ollama)
├─ /messages ─────────────────────► │ Selection: sticky -> least-pressure -> fallback
│ /anthropic/v1/… │ 429/5xx -> cooldown + pre-first-byte ms retry
└─ /models/<m>:streamGenerateC. ────► └─ 401 -> invalid · 403 -> (account x model) neg-cache
Core Architecture: Pool Failover, Protocol Translation & Multi-Provider Routing
1. Pre-First-Byte Failover Across 17+ Accounts
Managing a double-digit account pool manually is impossible. OpenSelect runs two synchronized relay layers:
- Proactive 45-Second Usage Polling & 97% Pre-Rotation: A background worker polls
GET /inference/go/v1/usageevery 45 seconds across all accounts, trackingrolling(5h),weekly, andmonthlypercentages plus reset countdowns (and restoring snapshots <24h old on restart so hot accounts aren't accidentally re-selected). Once any window crosses the threshold (default 97%, tunable from 95% to 99%), new sessions route viasticky->least-pressure->fallback. - In-Flight Pre-First-Byte Retry: If an active session hits upstream
429,401,403,5xx, a network drop, or even a2xxheader followed by a mid-stream stall before the first payload chunk, OpenSelect buffers the first chunk check and retries on the next healthy account (up to 4 attempts by default) before a single byte is flushed to the client. - Granular Error Isolation (Zero Good-Account Poisoning):
| Upstream Failure | OpenSelect Handling | Client Impact |
|---|---|---|
Upstream 429 (Rate Limit) | Parses retry-after + metadata.limitName, applies targeted cooldown, fails over immediately | Seamless continuation |
Upstream 401 (Invalid Key) | Marks account invalid out of rotation, retries next account (auto-recovers if later poll succeeds) | Seamless continuation |
Upstream 403 (Model/Region Block) | Never poisons the whole account; sets a 15-minute (account x model) negative cache and retries | Seamless continuation |
Upstream 5xx / Pre-First-Byte Drop | Short cooldown (<= 60s), logs original and failover account in ledger, retries | Seamless continuation |
Cloudflare 1010 Block | Normalizes upstream User-Agent: opencode/1.0.0 to avoid WAF script-signature blocks | Eliminates 1010 errors |
2. Zero-Config Claude Code Attachment & Local Protocol Translation
To run OpenAI-compatible coding models (deepseek-v4.1-flash, glm-5.1) directly inside Claude Code, :8788 acts as a dual Anthropic + OpenAI gateway:
- Native Anthropic Passthrough: Supports
POST /v1/messagesand/v1/messages/count_tokensacross 9family=anthropicmodels with zero translation overhead, synthesizing stablex-opencode-sessionheaders from credentials when omitted. - Built-In Anthropic-to-OpenAI Chat Translator: Point
ANTHROPIC_BASE_URLathttp://127.0.0.1:8788:
ANTHROPIC_BASE_URL=http://127.0.0.1:8788 ANTHROPIC_API_KEY=placeholder \
claude --model glm-5.1
The translator converts requests once locally (so failover retries reuse the translated payload with zero duplicate overhead), mapping mid-conversation system prompts, multi-turn history, image inputs, tools / tool_choice, tool_result, and stop_sequences, while normalizing OpenAI SSE streams — including interleaved or missing tool-call index fields — into valid Anthropic stream events.
- 1M Context Auto-Compact Trigger (
[1m]): Appending[1m](e.g.,deepseek-v4.1-flash[1m]) strips the suffix before forwarding and intercepts requests exceeding1,048,576tokens locally with a standard Anthropicprompt is too longresponse. Claude Code triggers/compactautomatically instead of slamming into an upstream400wall.
For terminal ergonomics, ./scripts/install-claude-aliases.sh backs up ~/.zshrc and installs three alias launchers with zero embedded secrets (actual credentials remain locked in 0600 ~/.openselect/config.json):
| Terminal Alias | Target Model | Intended Workflow |
|---|---|---|
ds-cli | deepseek-v4.1-flash[1m] | Primary fast Editor routed across the 17-account pool |
free-cli | deepseek-v4.1-flash-free | Zero-cost execution via free-tier routes |
auto-cli | coding-auto[1m] | Automatic cross-provider ladder (Z.ai -> MiniMax -> opencode-go -> DeepSeek Official) |
3. Multi-Provider Survival Ladder & free-first Mode
Beyond opencode-go, OpenSelect natively integrates five direct provider pools:
| Provider | Protocol Support | Example Model Aliases | Default Reasoning Injection | Quota / Health Endpoint |
|---|---|---|---|---|
| OpenCode Go | Anthropic / OpenAI / Google | All 37 catalog models | Native passthrough | GET /inference/go/v1/usage (5h/weekly/monthly) |
| Z.ai (GLM) | Native Anthropic | zai/glm-5.3-flash, zai/glm-5.3 | thinking.enabled + effort=max | GET /api/monitor/usage/quota/limit |
| MiniMax (CN/Global) | Native Anthropic | minimax/MiniMax-M3.1-Flash, M3 | output_config.effort=max | GET /v1/token_plan/remains |
| Command Code | Anthropic + OpenAI | cc/kimi-k3.1-pro, cc/glm-5.3-flash | Native passthrough | Multi-key failover per provider |
| Ollama Cloud | Anthropic + OpenAI | ollama/<auto-discovered> | Native passthrough | Auto-probes /v1/models |
| DeepSeek Official | Native Anthropic | deepseek/deepseek-flash, v4-pro | thinking.enabled + effort=max | GET /user/balance (CNY balance) |
Two details matter in production:
fallbackOnly=trueon Pay-As-You-Go APIs: Incoding-auto, requests traverse Z.ai GLM-5.3-Flash -> MiniMax M3.1-Flash ->opencode-godeepseek-v4.1-flash-> DeepSeek Officialdeepseek-flash. Marking DeepSeek Official asfallbackOnly=trueensures cash API balances are never touched until every subscription pool is exhausted.- Smart
429Cooldowns &free-firstIsolation: Direct providers only trigger long cooldowns when aretry-after/limitNameheader is present or quota hits 100% (bare transient429s pause just 3 seconds). Similarly,free-firsttries the 7opencode zenfree models plus verified Go free-tier models (longcat-2.5-preview-free,minimax-m3.1-flash-free) first, caching free-model failures per(account x free_model)for 15 minutes without cooling down the underlying paid account.
One-Command opencode Injection (opensel wire) & Telemetry Console (:8789)
During end-to-end testing, we confirmed a subtle opencode client quirk: opencode only honors model-level settings.baseURL overrides — provider-level settings.baseURL and legacy provider.options.baseURL are silently ignored.
Instead of hand-editing 37 model blocks, setup takes four commands:
git clone https://github.com/Acorne-VJ/OpenSelect.git
cd OpenSelect
./bin/opensel init
./bin/opensel import # Batch-import existing local opencode credentials
# or: ./bin/opensel add --key <KEY> --label go-01
./bin/opensel serve # Starts :8788 proxy + :8789 UI + 45s poller
./bin/opensel wire # Safely injects all 37 model baseURLs (reversible via unwire)
Before writing, opensel wire snapshots the original config to ~/.openselect/backups/ and tracks per-model state in wired.json, so ./bin/opensel unwire restores direct connections cleanly while preserving manual post-wire edits. Adding or removing accounts hot-reloads within one poll cycle, and ./bin/opensel install registers a macOS launchd service plus daily backups.
Opening http://127.0.0.1:8789 exposes the local cockpit:
- Pool Cockpit (
/): Live 5h/weekly/monthly progress bars, local-timezone reset timers, historical usage charts with threshold markers, active session pinning ("Set Preferred"), and a live price-performance table indexed to DeepSeek Official = 100%. - Token Analytics (
/tokens): Aggregates input, output, and cache tokens across providers, accounts, models, and clients with a 91-day activity heatmap (explicitly tagging translated-stream token counts as estimates). - Time-of-Day Route Optimizer (
/routes):bun run collect:pricingfetches peak vs. off-peak multipliers (such asopencode-godoubling DeepSeek token weights during peak hours) and scores routes by effective cost x pressure x latency x quality x reliability. - Catalog Sync, Diagnostics & Signed Backups:
opensel sync-catalog --writeunionsGET /v1/modelsacross accounts with zero-inference protocol probing,opensel doctoraudits the full chain, andopensel backupexports SQLiteVACUUM INTOsnapshots with Ed25519 signature verification and optional AES-256-CBC encrypted private Git backup.
FAQ
Does OpenSelect require Docker or external npm dependencies?
No. OpenSelect runs as a single Bun + TypeScript process with 0 runtime npm dependencies, using Bun's built-in bun:sqlite for state, telemetry, and snapshots, backed by 277 automated tests.
How does OpenSelect avoid dropping an active Claude Code session on a 429 error?
OpenSelect buffers the initial upstream response check before forwarding the first payload byte to the client. If an account returns 429, 401, 403, 5xx, or drops before the first body chunk, OpenSelect fails over to the next healthy account (up to 4 retries by default) without terminating the client session.
Why didn't setting a provider-level baseURL work in opencode?
End-to-end testing showed that opencode silently ignores provider-level settings.baseURL and legacy provider.options.baseURL, honoring only per-model settings.baseURL overrides. opensel wire automates injecting all 37 model entries reversibly via wired.json and ./bin/opensel unwire.
Will free-first failures lock out my paid opencode-go accounts?
No. When a free candidate model fails with 429, 403, or 5xx, OpenSelect records a 15-minute (account x free_model) negative cache entry and falls back immediately to the paid model without applying cooldowns to the account's paid quota pool.
Repository & Primary References
- GitHub Repository (MIT): Acorne-VJ/OpenSelect
- Primary X Thread: @AcornerVJ on X