If you received a "Publicly Exposed API Key" warning from Google, it is because your VITE_GEMINI_API_KEY was detected in the client-side code of your application.
Since this is a client-side application (Vite/React), the API key MUST be exposed to the browser to make requests to Gemini. This is normal architecture for serverless apps, but it requires specific security configurations to be safe.
The key that was detected is now compromised. You must revoke it immediately.
- Go to Google AI Studio API Keys.
- Find the key matching the warning.
- Click the trash icon to Delete it.
You need a new key that is restricted only to your specific websites.
- Click Create API Key.
- Click on the key to edit its settings (or view in Google Cloud Console).
- Under Application restrictions, select Websites.
- Add the following items to Website restrictions:
http://localhost:3000/*(For local development)https://your-production-url.com/*(Add your actual Vercel/Netlify URL here when deployed)
- Save the changes.
- Open your
.env(or.env.local) file. - Replace the old key with your new restricted key:
VITE_GEMINI_API_KEY=your_new_restricted_key_here
- Restart your dev server:
npm run dev
- Ensure
.envis listed in your.gitignorefile (it likely already is). - NEVER commit your
.envfile to GitHub.