Skip to content

Commit

Permalink
AIX: OpenRouter: multi-key support. See #653
Browse files Browse the repository at this point in the history
  • Loading branch information
enricoros committed Jan 15, 2025
1 parent 04e54d8 commit 30ac3f8
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/modules/llms/server/openai/openai.router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -496,8 +496,18 @@ export function openAIAccess(access: OpenAIAccessSchema, modelRefId: string | nu
};

case 'openrouter':
const orKey = access.oaiKey || env.OPENROUTER_API_KEY || '';
let orKey = access.oaiKey || env.OPENROUTER_API_KEY || '';
const orHost = fixupHost(access.oaiHost || DEFAULT_OPENROUTER_HOST, apiPath);

// multi-key with random selection
if (orKey.includes(',')) {
const multiKeys = orKey
.split(',')
.map(key => key.trim())
.filter(Boolean);
orKey = multiKeys[Math.floor(Math.random() * multiKeys.length)];
}

if (!orKey || !orHost)
throw new Error('Missing OpenRouter API Key or Host. Add it on the UI (Models Setup) or server side (your deployment).');

Expand Down

0 comments on commit 30ac3f8

Please sign in to comment.