big-AGI icon indicating copy to clipboard operation
big-AGI copied to clipboard

[Roadmap] multiple Gemini API keys

Open darthalex2014 opened this issue 4 months ago • 0 comments

Why Users will be able to use multiple Gemini API keys to access the AI, allowing them to bypass rate limits and improve performance, especially when working with Beam and a single AI provider.

Description Add support for using multiple Gemini API keys in the application.

Requirements

  • [ ] Environment Variable:
    • Add a new environment variable GEMINI_API_KEYS in src/server/env.mjs to store a comma-separated list of API keys.
  • [ ] Key Selection Logic:
    • Modify the line const geminiKey = access.geminiKey || env.GEMINI_API_KEY || ''; in src/modules/llms/server/gemini/gemini.router.ts to:
  let geminiKey: string;
  if (access.geminiKey.includes(',')) {
    // If access.geminiKey includes commas, treat it as a list of keys and choose a random one
    const keys = access.geminiKey.split(',').map(key => key.trim()).filter(key => key.length > 0);
    geminiKey = keys[Math.floor(Math.random() * keys.length)];
  } else {
    // Otherwise, treat it as a single key
    geminiKey = access.geminiKey;
  }

image

darthalex2014 avatar Sep 30 '24 15:09 darthalex2014