You've added: AIzaSyClkP29LlTNu833ZFObivr6LuwBOdq59_E
Make sure your backend/.env file looks exactly like this (no spaces around =):
PORT=5000
GOOGLE_GEMINI_API_KEY=AIzaSyClkP29LlTNu833ZFObivr6LuwBOdq59_EImportant:
- No spaces before or after the
=sign - No quotes around the API key
- No trailing spaces
IMPORTANT: After adding/changing the .env file, you MUST restart the backend server:
-
Stop the backend server (press
Ctrl+Cin the terminal) -
Start it again:
cd backend npm start -
You should see:
✓ Google Gemini API key found
-
Make sure backend is running
-
Open browser and go to:
http://localhost:5000/api/test-gemini -
You should see a JSON response:
- If working:
{"success": true, "message": "Gemini API is working!"} - If error: Check the error message
- If working:
- Open frontend:
http://localhost:3000 - Click the chatbot button (💬)
- Ask: "Hello"
- Check backend terminal for logs:
- Should see: "Attempting to use Google Gemini API..."
- Should see: "Gemini API success!"
Symptoms:
- Backend shows: "GOOGLE_GEMINI_API_KEY not found"
- Chatbot uses fallback assistant
Solution:
- Check .env file is in
backend/.env(notbackend/backend/.env) - Make sure no spaces around
= - Restart backend server
Symptoms:
- Error: "API key not valid" or "401" or "403"
Solution:
- Verify API key is correct (no typos)
- Check if API key is enabled in Google Cloud Console
- Make sure Gemini API is enabled for your project
Symptoms:
- Error: "404" or "model not found"
Solution:
- The code will automatically try
gemini-1.5-flashfirst, thengemini-pro - Both should work, but if not, check your API key permissions
Symptoms:
- Error: "429" or "rate limit"
Solution:
- Free tier has rate limits
- Wait a few minutes and try again
- Or upgrade your Google Cloud plan
-
Check .env file location:
cd backend cat .envShould show your API key
-
Check if server reads it:
- Look for "✓ Google Gemini API key found" when starting backend
-
Test API directly:
- Visit:
http://localhost:5000/api/test-gemini - Check the response
- Visit:
-
Check backend logs:
- When you send a chat message, check backend terminal
- Look for error messages
-
Check browser console:
- Open DevTools (F12) → Console tab
- Look for error messages
-
Verify API key is valid:
- Go to: https://makersuite.google.com/app/apikey
- Check if your key is listed and active
-
Check API is enabled:
- Go to: https://console.cloud.google.com/apis/library
- Search for "Generative Language API"
- Make sure it's enabled
-
Try regenerating API key:
- Create a new key
- Update .env file
- Restart backend
-
Check backend terminal output:
- Share the exact error message you see
- This will help diagnose the issue
Run this in your browser (while backend is running):
http://localhost:5000/api/test-gemini
This will tell you exactly what's wrong with the API key!