feat: support multiple API keys for LLM providers, allowing automatic key rotation on failure

This commit is contained in:
2026-05-12 07:09:20 +00:00
parent 50f422f0d3
commit 1b7aeedfdb
6 changed files with 55 additions and 28 deletions
+10 -3
View File
@@ -26,14 +26,14 @@ describe('getLLMConfig', () => {
it('returns null provider when no env vars set', () => {
const cfg = getLLMConfig();
assert.equal(cfg.provider, null);
assert.equal(cfg.apiKey, null);
assert.deepEqual(cfg.apiKeys, []);
});
it('detects openai with defaults', () => {
process.env.OPENAI_API_KEY = 'sk-test';
const cfg = getLLMConfig();
assert.equal(cfg.provider, 'openai');
assert.equal(cfg.apiKey, 'sk-test');
assert.deepEqual(cfg.apiKeys, ['sk-test']);
assert.equal(cfg.baseURL, 'https://api.openai.com/v1');
assert.equal(cfg.model, 'gpt-4o-mini');
});
@@ -48,7 +48,14 @@ describe('getLLMConfig', () => {
assert.equal(cfg.model, 'gpt-4o');
});
it('detects gemini with defaults', () => {
it('detects gemini with comma-separated keys, picks one', () => {
process.env.GEMINI_API_KEY = 'key1,key2,key3';
const cfg = getLLMConfig();
assert.equal(cfg.provider, 'gemini');
assert.deepEqual(cfg.apiKeys, ['key1', 'key2', 'key3']);
});
it('detects gemini with single key (no comma)', () => {
process.env.GEMINI_API_KEY = 'gemini-key';
const cfg = getLLMConfig();
assert.equal(cfg.provider, 'gemini');