Is My Gemini API Key Safe in My App?
Short answer: not if it's in your front-end code. Google says to treat your Gemini API key like a password. If your app calls Gemini straight from the browser, anyone can pull the key out and use it on your bill. Move the calls to a server and keep the key there.
Check your live app for free
Paste your link. The free summary usually takes under a minute.
See an example report (for example.org) · a real free scan of a test site, so you can see what you get
Why this comes up
You ask Lovable, Bolt, Cursor or a similar tool to "add an AI chat" or "summarize this with Gemini." A simple way to make that work is to call Gemini right from the page, with the key pasted in. It works on day one. But the page's code is sent to every visitor's browser, and the key goes with it.
What Google says
Google's Gemini key page is clear: "Treat your Gemini API key like a password. If compromised, others can consume your project's quota, incur unexpected billing charges, and access private resources."
And in its critical security rules: "Never expose keys client-side in production: Do not hardcode API keys directly in web or mobile apps. Keys compiled in client-side code can be extracted by users. To secure client-side apps, run a backend proxy server to make the actual API calls."
(Google AI for Developers: Using Gemini API keys)
A "backend proxy server" just means your own server code (for example a Supabase Edge Function or a server API route) that holds the key and calls Gemini for your app. The browser talks to your server, never to Gemini with your key.
"But my env variable is hidden, right?"
Not always. Putting the key in an environment variable keeps it out of your code files. But in front-end tools like Vite or Next.js, some variables are copied into the code that goes to the browser.
Vite's docs say: "Variables prefixed with VITE_ will be exposed in client-side source code after Vite bundling." They also say: "VITE_* variables should not contain sensitive information such as API keys. The values of these variables are bundled into your source code at build time." (Vite: Env Variables and Modes)
Next.js lists this as a built-in feature: "Bundle environment variables for the browser by prefixing with NEXT_PUBLIC_". And: "these public environment variables will be inlined into the JavaScript bundle during next build." (Next.js: How to use environment variables)
If the page calls Gemini directly, the key has to be in the browser for that to work, so it's public no matter where you stored it.
How to check your app
- Ask your AI builder. Paste this:
Find every place my app uses a Gemini or Google AI API key. For each one, tell me: is the key used in code that runs in the browser, or only in server code (an Edge Function or server API route)? Check environment variables that start with VITE_ or NEXT_PUBLIC_ too. Don't change any code yet.- Run the free scan. Paste your URL in the box at the top. It looks for Google API keys in the HTML tags on the page (including tag attributes), the inline scripts on that page, and up to 15 script files from your own site. More on what it can and can't see is below.
How to fix it
If the key is in your front-end code:
- Move the Gemini calls to a server. Paste this:
Move all Gemini API calls out of my front-end code into a server function (a Supabase Edge Function or a server API route). Store the Gemini key as a server-only secret, not in any VITE_ or NEXT_PUBLIC_ variable. Have my app call my server function instead, and only let logged-in users call it. Then show me that no Gemini key is left in any file that runs in the browser.- Treat the old key as leaked. Google's leak checklist says to make a new key, update your app, then turn off the old one. In Google's words: "Disable the leaked key in the Cloud console once the new key is verified. Do not delete the old key until the new key is fully active to avoid application downtime." Then: "Check billing logs and API usage in the Google Cloud console to identify unauthorized activity."
- Restrict the key. Google says: "Adding restrictions to your API keys minimizes the potential damage if a key is compromised." In Google AI Studio you can mark a key Restrict to Gemini API only. Google also says, "The Gemini API rejects requests from unrestricted standard keys." So an unrestricted standard key may stop working anyway.
- Set a billing alert. Google lists this as a best practice: "Set up billing alerts in the Google Cloud console to notify you if usage or costs spike." See also How do I stop a surprise bill on my vibe-coded app?
(Google AI for Developers: Using Gemini API keys)
Things to watch for
- Don't share one key between Maps and Gemini. A Google Maps key is meant to sit in the browser, locked to your site. A Gemini key is not. Google calls sharing one key with other Google APIs "not recommended." Use separate keys. See Is my Google Maps API key safe to expose?
- Don't put the key in Git. Google says: "Never check API keys into source control systems like Git."
- Your server function needs limits too. Once Gemini runs through your server, anyone who can reach that function can still run up costs. Require a login and limit how often each user can call it.
What the rooGBotVC scan checks
Paste your URL in the box at the top. The scan reads the HTML tags on the page you scan (including tag attributes), the inline scripts on that page, and up to 15 script files from your own site.
- If it finds a Google API key (one that starts with
AIzafollowed by 35 more letters, numbers, dashes or underscores), it shows "Google API key in public code" (low). The scan can't tell a Gemini key from a Maps key, since both can look the same. So if you see this, check what that key is for. If it's a Gemini key, follow the fix steps above. - If your app also has a Firebase config, the scan shows "Firebase config found: check your Security Rules" instead of the Google key finding, so check your Gemini key yourself with the prompt above.
What the scan can't do:
- It doesn't run your JavaScript, so a key that only shows up after the page runs, or that is loaded from another site, may be missed.
- It only looks for keys that start with
AIzafollowed by 35 more letters, numbers, dashes or underscores. If your Gemini key looks different, the scan may not catch it. - It can't see your Google Cloud or AI Studio settings, so it can't tell whether a key is restricted or how much it has been used.
- It never uses or tests any key it finds.
- It doesn't test logins, rate limits, billing or RLS.
Related reading
- Exposed API keys: what to do when any key leaks.
- Is my OpenAI API key safe in my app?: the same idea for an OpenAI key.
- Is my Claude API key safe in my app?: the same idea for an Anthropic Claude key.
- Is my Google Maps API key safe to expose?: the Google key that is meant to be public, if you lock it down.
- Is my Grok (xAI) API key safe in my app?: the same idea for an xAI Grok key.
- How do I stop a surprise bill on my vibe-coded app?: budgets and alerts.
- Are your source maps public?: another way your code can show more than you think.
- Is my Firebase API key safe to expose?: a Google key that is meant to be public; your Security Rules are the lock.
The bottom line
A Gemini key in front-end code is a public key, and Google says not to do it. Move Gemini calls to your own server, make a new key, turn off the old one, restrict it to the Gemini API and set a billing alert. Then paste your URL in the box at the top to check what your app shows the public.
Related guides
This is an automated, surface-level check of what your site shows the public. It is not a full security audit.