Skip to content

feat: multi-key round-robin per provider (C5)#14

Merged
MANVENDRA-github merged 1 commit into
mainfrom
feat/multikey-roundrobin
Jun 30, 2026
Merged

feat: multi-key round-robin per provider (C5)#14
MANVENDRA-github merged 1 commit into
mainfrom
feat/multikey-roundrobin

Conversation

@MANVENDRA-github

Copy link
Copy Markdown
Owner

Lets a provider hold a pool of API keys and rotates across them per request, so
free-tier users can spread load over several keys instead of hammering one key's
limit. (Closes the round-robin gap from the v0.1.x audit.)

What changed

  • Config: providers accept apiKeyEnvs (an array) alongside apiKeyEnv;
    ResolvedProvider.apiKeyapiKeys: string[] (unset/empty env vars skipped).
  • Adapters take an ApiKeySource (a fixed string OR a supplier); the registry
    builds a round-robin supplier over the resolved pool, so each outbound call
    picks the next key. Single-key and keyless providers behave exactly as before.
  • Docs/example: apiKeyEnvs on the Gemini example + GEMINI_API_KEY_2 in
    .env.example; README note; SECURITY_REVIEW_LOG SR-008 (wider secret surface).

Follow-up (not in this PR): on a 429, retry the next key before model fallback
(needs executor/adapter awareness) — today rotation is per-request distribution.

Tests

  • config resolves a pool from apiKeyEnvs (+ apiKeyEnv, skipping empties);
    the registry round-robins keys across successive requests (k1 → k2 → k1) and
    sends no auth header for a keyless pool.

How to verify

  • pnpm verify → green (233 tests, coverage ≥90%)
  • pnpm build → green

Lets a provider hold a pool of API keys and rotates across them per request, so
free-tier users can spread load over several keys instead of hammering one key's
limit. (Closes the round-robin gap from the v0.1.x audit.)

What changed
- Config: providers accept `apiKeyEnvs` (an array) alongside `apiKeyEnv`;
  `ResolvedProvider.apiKey` → `apiKeys: string[]` (unset/empty env vars skipped).
- Adapters take an `ApiKeySource` (a fixed string OR a supplier); the registry
  builds a round-robin supplier over the resolved pool, so each outbound call
  picks the next key. Single-key and keyless providers behave exactly as before.
- Docs/example: `apiKeyEnvs` on the Gemini example + `GEMINI_API_KEY_2` in
  `.env.example`; README note; SECURITY_REVIEW_LOG SR-008 (wider secret surface).

Follow-up (not in this PR): on a 429, retry the *next key* before model fallback
(needs executor/adapter awareness) — today rotation is per-request distribution.

Tests
- config resolves a pool from `apiKeyEnvs` (+ `apiKeyEnv`, skipping empties);
  the registry round-robins keys across successive requests (k1 → k2 → k1) and
  sends no auth header for a keyless pool.

How to verify
- `pnpm verify` → green (233 tests, coverage ≥90%)
- `pnpm build`  → green
@MANVENDRA-github
MANVENDRA-github merged commit 478faad into main Jun 30, 2026
2 checks passed
@MANVENDRA-github
MANVENDRA-github deleted the feat/multikey-roundrobin branch June 30, 2026 17:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant