anomalyco / anomalyco/opencode

[FEATURE]:Native API Key Pool & Automatic Failover to Prevent Rate Limit Task Failures

Open
#42,502 5 comments 1 reaction 1 assignee View on GitHub

@kitlangton is already working on this.

Since Aug 14, 2026.

Dominant language
TypeScript
Stars
209k
Forks
27.5k
PR merge metrics
PR metrics pending

Description

Problem

Currently, OpenCode only supports a single API key per model provider. When that key hits a rate limit (HTTP 429), runs into a server error (500), or exhausts daily quota, any active agent task stops immediately with no way to recover automatically.

For long, complex coding tasks, this is very disruptive — you lose progress mid-work and have to manually restart the session, which defeats the purpose of an autonomous coding agent. There's no built-in way to work around rate limits short of manually swapping keys, which breaks the native workflow.

I know issue #7602 covers model-level fallback, but this request focuses specifically on key-level pooling and failover within the same provider/model, which is a more targeted fix for everyday rate limit issues.

Proposed Solution

Add a native API key pool manager directly at the LLM adapter layer, with these core capabilities:

  1. Multi-key rotation: Let users configure a list of multiple API keys for the same provider, with round-robin distribution to spread out request load.
  2. Instant failover: Automatically retry requests that return 429 or 500 status codes with a different key from the pool, so the agent loop continues without interruption.
  3. Smart cooldown: Temporarily remove throttled keys from rotation for a short window (default 60s, or following the Retry-After response header if provided).
  4. Quota tracking: Automatically disable keys that hit their daily quota limit until midnight UTC reset, with an option for manual re-enablement.
  5. TUI status display: Show real-time key status (active / cooling down / quota exhausted) directly in the terminal interface for transparency.
Additional Notes

Separately, I think there are other worthwhile efficiency improvements for OpenCode — like better prompt caching via context diffing, a tree-sitter based repo map to reduce context bloat, and per-step reasoning effort controls. I've focused this issue on key pooling since it's the most immediate reliability problem for me, but I can open separate, focused issues for those other ideas if there's interest.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.