debug: add API key source logging

This commit is contained in:
Christian Vidal Wolf
2026-04-24 13:28:01 +02:00
parent 2c1efc44d6
commit 3bc2753bec
2 changed files with 15 additions and 12 deletions
+10 -7
View File
@@ -1,16 +1,19 @@
export async function generateGemini(prompt: string, systemPrompt: string): Promise<string> {
// Try all possible ways to get the API key
let keySource = 'none';
const apiKey =
(window as any).GEMINI_API_KEY ||
localStorage.getItem('GEMINI_API_KEY') ||
import.meta.env.VITE_GEMINI_API_KEY ||
import.meta.env.GEMINI_API_KEY ||
(process.env as any).GEMINI_API_KEY ||
(window as any).GEMINI_API_KEY ? (keySource = 'window', (window as any).GEMINI_API_KEY) :
localStorage.getItem('GEMINI_API_KEY') ? (keySource = 'localStorage', localStorage.getItem('GEMINI_API_KEY')) :
import.meta.env.VITE_GEMINI_API_KEY ? (keySource = 'import.meta.env.VITE_GEMINI_API_KEY', import.meta.env.VITE_GEMINI_API_KEY) :
import.meta.env.GEMINI_API_KEY ? (keySource = 'import.meta.env.GEMINI_API_KEY', import.meta.env.GEMINI_API_KEY) :
(process.env as any).GEMINI_API_KEY ? (keySource = 'process.env', (process.env as any).GEMINI_API_KEY) :
'';
console.log(`[Gemini] API Key source: ${keySource}`);
if (!apiKey) {
console.error('No Gemini API Key found in env or storage');
throw new Error('Gemini API Key not found. Please set VITE_GEMINI_API_KEY in .env or GEMINI_API_KEY in localStorage.');
console.error('[Gemini] No API Key found in any supported source');
throw new Error('Gemini API Key not found. Please set VITE_GEMINI_API_KEY in .env or your environment variables.');
}
// Model fallback list - using current stable and experimental versions