diff --git a/src/services/gemini.ts b/src/services/gemini.ts index f6be644..c8c793d 100644 --- a/src/services/gemini.ts +++ b/src/services/gemini.ts @@ -1,7 +1,16 @@ export async function generateGemini(prompt: string, systemPrompt: string): Promise { - const apiKey = import.meta.env.GEMINI_API_KEY || localStorage.getItem('GEMINI_API_KEY') || ''; + // Try all possible ways to get the API key + 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 || + ''; + if (!apiKey) { - throw new Error('Gemini API Key not found. Please set GEMINI_API_KEY in .env or GEMINI_API_KEY in localStorage.'); + 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.'); } const response = await fetch(`https://generativelanguage.googleapis.com/v1beta/models/gemini-2.0-flash-exp:generateContent?key=${apiKey}`, {