Checklist
Leaked Gemini API key? What to do right now
Short answer. Treat the key as copied. Google says a Gemini API key can spend the project's quota and run up the bill. Create a replacement in Google AI Studio, deploy it from the server, then disable the old key in Google Cloud. A Firebase web apiKey restricted to Firebase APIs is a different value and is not this leak.
Updated 30 Nov 2026
This is a practical checklist, not a guarantee. It is not a penetration test, a compliance audit, or proof that an app is safe to launch.
A Gemini API key is a credential for the Gemini API. Google's API key guide says to treat it like a password: if someone else has it, they can consume the project's quota and incur unexpected billing charges. Deleting the line from a file does not retire the key. This page is the first sitting after a leak. It is a checklist, not a statement that the project is fine.
The same shape for other credentials is Leaked OpenAI API key?, Leaked a GitHub token?, and API keys in the frontend.
Create a new key, then disable the old one
Google's leak checklist, on that same page, is in this order. Do it before you rewrite git history.
1. Create a replacement in Google AI Studio or on the Google Cloud credentials page. Since 28 May 2026, new keys created in AI Studio are authorization keys. Those are bound to a service account, restricted to the Generative Language API by default, and Google says they get fast-acting enforcement that stops leaked keys its systems detect. Standard keys only tie the call to a project for billing and quota. The Gemini API rejects unrestricted standard keys. A standard key that already has explicit restrictions still works. 2. Put the new key in the server environment as GEMINI_API_KEY or GOOGLE_API_KEY. Google's client libraries read those names. Deploy the app so the server uses the new value. On Vercel, an environment variable change applies only to a new deployment. Vercel's environment variables page says the running deployment keeps the value it was built with. 3. After the new key works, disable the leaked key in the Cloud console. Google says not to delete the old key until the new one is fully active, so the app does not go down in between. Delete it once you have confirmed the new key. A key deleted more than 30 days ago no longer shows in AI Studio's unknown-keys list. 4. Check billing logs and API usage in the Google Cloud console for calls you did not make. Google also says to set billing alerts there. Cloud Billing documents budgets and budget alerts for that.
AI Studio only lists keys that are unrestricted or restricted to the Generative Language API. Keys with other restrictions are on the Cloud credentials page. Restricting a key requires apikeys.keys.update on the project.
Restrict what the new key can call
Google says restrictions limit the damage if a key leaks again.
- In AI Studio, keys marked for it can be set to Restrict to Gemini API only.
- In Cloud console, open the key, then API restrictions, then Restrict key, and select only the APIs that key should call. Do not leave a Gemini key able to call every API enabled on the project.
- Under Application restrictions, limit which IP addresses, websites, or apps can use the key. Google's steps use IP addresses for a server. Pick the type that matches where the key actually runs.
A key you also use for other Google APIs is the case Google says not to recommend. Restrict that key in the Cloud console for those other APIs, and create a separate Gemini key in AI Studio.
Get it out of the client and out of git
Google says not to hardcode a Gemini key in a web or mobile app in production. A key compiled into client code can be extracted. The documented path is a backend proxy: the browser calls your server, and the server holds the key. NEXT_PUBLIC_ and VITE_ names are inlined into that bundle. They are the wrong place. The passes are API keys in the frontend and how to keep API keys out of AI-generated code.
Lovable, Bolt, v0, and Cursor will paste a key into a component if the prompt asked the browser to call Gemini. Move that call to a server route or an edge function. Do not commit .env.
GitHub's removing sensitive data page says to revoke or rotate first. After the key is disabled, rewriting history may not be worth it. A force-push does not erase clones, forks, or commits still fetchable by SHA. The same limit is in Leaked a GitHub token?.
This is not the Firebase web apiKey
Firebase's API keys page says a key restricted to Firebase APIs only identifies the project. That key can sit in the web config. A Gemini Developer API key cannot. In the Cloud console it is named Gemini API Key or Gemini Developer API key (auto created by Firebase), and it is restricted to Generative Language API. Do not add Generative Language API to a public Firebase key. The split is Is the Firebase API key safe to expose?.
If the app calls Gemini through Firebase AI Logic, Firebase's FAQ says that since mid-2026 that path uses a Google-managed service account, not a standard Gemini API key you paste into the client. You still enforce App Check. Firebase's App Check page says requests without a valid attestation are rejected when App Check is enforced, and that on 2 Nov 2026 Firebase turned that enforcement on for Firebase AI Logic projects. Replay protection makes an App Check token usable once. That is the documented way to call Gemini from the app itself. A raw key in the bundle is not.
Then run a free passive check on the public URL. It can see a key that shipped in a script. It does not read your Google Cloud project. The worksheets are the checklist pack and the pre-launch checklist.
FAQ
I deleted the key from the repo. Is the Gemini key dead?
No. Create a new key, deploy it, then disable the old one in the Cloud console. Google says not to delete the old key until the new one is active. A copy in git history, a fork, or the current deployment keeps working until the old key is disabled. Removing the line is the cleanup after that.
Does restricting the key to the Gemini API stop a leak?
It stops that key from calling other Google APIs. It does not stop someone from calling Gemini with it and spending your quota. Google still says to disable a key you think has leaked. Authorization keys get faster automatic blocking when Google's systems detect a leak. A standard key does not identify who called.
Is the Firebase apiKey the same as a Gemini key?
No. A Firebase web apiKey limited to Firebase APIs identifies the project. A Gemini key, including one Firebase auto-created for the Gemini Developer API, is a secret and must stay off the client. Do not add Generative Language API to the Firebase key's allowlist.
Can the browser call Gemini directly?
Google says not to put the API key in client-side code in production. Use a server route or an edge function that holds the key. If you want the app itself to call Gemini, Firebase AI Logic with App Check enforced is the path Firebase documents, and that path no longer uses a standard API key you embed.
Sources
Checked 30 Nov 2026.
Informational only. This page describes checks and vendor documentation. It is not a security audit, a penetration test, or a certification, and it is not a guarantee.
Newsletter
A short weekly note on new tools and security checklists. No spam, unsubscribe anytime.