Home / Guides / Google API keys and Gemini: lock them down now

Google API keys and Gemini: lock them down now

Gemini now rejects unrestricted Google API keys, but an AIza key whose restrictions include Gemini still works. How to restrict every key in about 10 minutes, and when to rotate.

Uses 1 of your 3 free scans today; a site scanned in the last 24 hours answers from that scan. Passive and read-only: we only look at what any browser can see. Only check sites you own or may test.

What the free scan checks

  • Leaked keys in your live JavaScript (AI, payment and cloud keys), including a Supabase service_role key
  • Files that should never be public, like /.env and /.git
  • Supabase and Firebase secrets in the browser: an sb_secret_ key, a Supabase access token or a Firebase service-account file
  • HTTPS and security headers (CSP, HSTS, clickjacking protection)

It only reads what any visitor's browser can see. It doesn't log in, read your tables or check App Check.

Threat brief · updated Oct 26, 2026

What it is: a Gemini API key shipped in your page or JavaScript, where anyone can copy it and run Gemini on your bill. Since May 28, 2026, new keys created in Google AI Studio are auth keys, which look like AQ.Ab…, not the older AIza… (Google, Using Gemini API keys).

Who's affected: apps that call Gemini straight from the browser, often through a VITE_ or NEXT_PUBLIC_ variable, plus any older AIza key whose API restrictions include Gemini (below).

Safe self-check

Search your own built files for either key format. It prints only the first characters of anything it finds.

Terminal (in your project)
grep -rEo "AQ\.Ab[A-Za-z0-9_-]{6}|AIza[0-9A-Za-z_-]{6}" dist/ build/ .next/static/ 2>/dev/null | sort -u

No output means no key in those folders. Any line means a key is in what you ship: move it server-side and replace it.

New key format: AQ. auth keys

API restrictions don't make an AQ. key safe to publish: it is a Gemini credential. If one was ever in your public code, delete it in Google AI Studio, create a new one and keep it server-side (an Edge Function or API route).

What changed

For years Google said keys that start with AIza (Maps, Firebase and so on) were fine to put in your website. Then Gemini started accepting the same keys. At the time, when someone enabled the Gemini (Generative Language) API on a Google Cloud project, existing unrestricted keys in that project quietly gained Gemini access, with "no warning", "no confirmation dialog" and "no email notification" (Truffle Security).

Google has since tightened this. The Gemini API now rejects requests from unrestricted standard keys, while standard keys with explicit restrictions keep working (Gemini API key docs). So a key whose API restrictions include the Generative Language API still works for Gemini. Keys that Firebase creates for you have been restricted to Firebase-related APIs automatically since May 2024; keys you made yourself in the Cloud console were not changed (Firebase docs).

Researchers found about 2,800 public keys that could access Gemini, including some of Google's own (Malwarebytes). With a key that has Gemini access, an attacker can access files you uploaded to Gemini and run up your AI bill (Truffle Security).

Google's current rules

What to do (about 10 minutes)

  1. Open Google Cloud Console → APIs & Services → Credentials for each project.
  2. For each key, set API restrictions so only the APIs it needs (Maps, Firebase and so on) are allowed, and make sure Generative Language API is not on the list (Google Cloud blog).
  3. Add Application restrictions (your website's domain) where you can.
  4. If you use Gemini, create a separate key, keep it in a server-side secret (an Edge Function or API route) and never in a VITE_ or NEXT_PUBLIC_ variable.
  5. If a key with Gemini access was ever in your public code, rotate it. Start with your oldest keys (Truffle Security).

Scan your app free

ShipLatch checks your live site for leaked keys, public env values, source maps and exposed files. The $29 Fix Pack gives you fix prompts written for your app and re-scans that prove each fix worked.

Scan free at shiplatch.com → See the Fix Pack · $9 playbook

Questions

What does a new Gemini API key look like?

Keys created in Google AI Studio since May 28, 2026 are auth keys that start with AQ.Ab, according to Google's Gemini API key docs and the gemini-cli project. Older Google keys start with AIza.

Can I put a Gemini API key in my frontend?

No. Google says never to expose keys client-side in production, because anyone can extract them. Call Gemini from a backend or edge function and keep the key there.

Want the whole pre-launch process in one place? See what's inside App Security for Vibe Coders, our $9 PDF playbook, or go straight to checkout.

More guides