Skip to content
prune.

Gemini API key leaked: what to do in the first hour

Stop the spend first, then find the leak, then build the evidence for a refund.

Quick answer

Delete or regenerate the leaked key now, then restrict every remaining key in the project to the Gemini API only. Set a monthly spend cap on the project in Google AI Studio, because Cloud Billing budgets only alert. Then find how the key leaked, and file a billing dispute as fraudulent use of a compromised key, with your normal spend as evidence.

Why this is urgent

Attackers scrape GitHub, app bundles, and frontend code for keys and use them for the most expensive calls, often image and video generation. In 2026, developers on r/googlecloud reported bills like $82,314 in 48 hours against a normal $180 a month, and about $128,000 in another case. A common thread: old keys, sometimes created years ago for Maps or Firebase, that were never restricted and quietly gained Gemini access.

1. Kill the key

In Google AI Studio or Cloud Console (APIs & Services, Credentials), delete or regenerate the leaked key. Note the exact time you did it; you will need it for the dispute. Requests already in flight can still finish, so watch usage for the next hour.

2. Restrict every other key

The leaked key is rarely the only weak one. List all keys in every project that has the Generative Language API enabled. Restrict each one to only the APIs it needs, and delete the ones nobody uses. Keys created in AI Studio are restricted to the Gemini API by default; older Cloud keys often are not, and Google now rejects unrestricted keys on the Gemini API.

audit-keys.sh
# Every key in the project, with its restrictions
gcloud services api-keys list --project=YOUR_PROJECT

# Restrict a key to the Gemini API only
gcloud services api-keys update KEY_ID \
  --project=YOUR_PROJECT \
  --api-target=service=generativelanguage.googleapis.com

# Delete a key you no longer need
gcloud services api-keys delete KEY_ID --project=YOUR_PROJECT

3. Put a hard ceiling on usage

A Cloud Billing budget is an email, not a brake. Since March 2026, Google AI Studio has a real one: open the project's Spend tab and set a monthly spend cap. It applies with about a 10 minute delay, and you pay for anything spent in that window, which at stolen-key speeds can still be a lot. So also lower the quotas on the Generative Language API (requests per minute and per day) to what your app actually needs.

4. Find the leak

  • Git history, including deleted files and old branches. Removing the file later does not remove it from history.
  • Frontend bundles and mobile apps. Any key shipped to a browser or APK is public.
  • CI logs, shared notebooks, screenshots, and pasted errors in issues or Discord.
find-leak.sh
# Search the full git history for leaked secrets
gitleaks git .            # or: trufflehog git file://. --only-verified

# Google API keys start with AIza. Look in built bundles too.
grep -rn "AIza" dist/ build/ .next/ android/ ios/ 2>/dev/null

If you see API key was reported as leaked, Google already found the key in public and blocked it. Treat it as compromised even if the bill looks normal.

5. File the billing dispute with evidence

Open a billing support case labelled as fraudulent charges from a compromised API key, not a general billing question. Include your normal monthly spend, the exact abuse window from Billing reports, the SKUs that spiked, and when you revoked the key. Developers report mixed outcomes, from full refunds to partial credits to denials, so the cleaner the evidence, the better your odds.

6. Keep the next key out of reach

Never ship a Gemini key to a browser or mobile app. Call Gemini from your server, keep the key in a secret manager, and for Firebase apps use App Check. Give each app its own restricted key with its own quota, so one leak cannot drain everything.

Where Prune fits

Prune is an AI gateway. Your Gemini key goes into Prune's encrypted vault (AES-256-GCM) and your code only holds a Prune key. If that Prune key leaks, you revoke it in the dashboard; your Gemini key never left the vault. A per-key daily spend cap and spike detection (Shield, Balanced or Locked down) reject calls before they reach Google, so a stolen key cannot run past the number you set. New accounts start on Balanced ($200/day). Accounts created before October 2026 should open Shield and pick a mode.

Gemini through Prune works for standard and streaming calls. Save your Gemini key under Connect, Providers, then follow the quick start.

With a single line of code, Prune cuts your AI bill and protects your team from runaway spend, leaked keys and dangerous calls.

Related

Have an account? Sign in · PyPI.