ospalabs
Guide · Gemini

Gemini API key leaked? What to do in the first hour

Updated October 2026

A Gemini API key (it starts with AIza) works for anyone who has the string, on your billing account, until you delete it. Bots scan public GitHub repos and shipped JavaScript for these keys, and a leaked key can be in use within minutes.

Do it in this order: stop the key, find out what it cost, then set things up so the next leak can only spend a small, fixed amount.

  1. 01

    Delete or regenerate the key now

    Open the API keys page in Google AI Studio, or APIs & Services → Credentials in the Google Cloud console for the same project, and delete the key. Removing the commit or the file is not enough: the key stays valid, and copies live on in git history, forks and caches.

  2. 02

    Replace it everywhere it was used

    Create a new key and update every place that held the old one: server environment variables, CI secrets, serverless functions. If the key was inside a web page or a mobile app, move the Gemini call to your server instead; a key shipped to users can always be pulled back out.

  3. 03

    Check what the leak cost

    In Cloud Billing → Reports, filter by the project and by the Gemini API (Generative Language API) service, and look at the hours since the key went public. Google's billing data can lag by hours, so look again the next day. If you see usage that isn't yours, open a case with Google Cloud billing support.

  4. 04

    Restrict and cap the replacement

    On the new key, add an API restriction so it can only call the Generative Language API. Google now offers spend cap budgets for the Gemini API (a preview feature at the time of writing); set one on the project. Caps that act on billing data can trail fast spend, so treat them as a backstop rather than the only line.

  5. 05

    Keep the real key out of your apps

    Store the Gemini key in a Fuse project and give each app a Fuse key instead. Every request is checked against a daily or monthly dollar ceiling before it is sent. If a Fuse key leaks, it can spend at most what's left under the ceiling or its own cap, and you revoke it in one click while the Gemini key never moves.

    .env
    FUSE_BASE_URL=https://fuse.ospalabs.com/v1
    FUSE_API_KEY=fz_your_fuse_key

Questions

Will Google refund charges from a leaked key?
Sometimes, case by case, through Google Cloud billing support. There's no promise, so stopping the key quickly and capping the next one matters more than the refund request.
Is deleting the commit enough?
No. The key keeps working until you delete it in AI Studio or the Cloud console. Delete the key first; cleaning git history is optional after that.
Can I use a restricted key in a browser or mobile app?
Restrictions lower the risk but the key can still be extracted from the app. Call Gemini from your own server, or through Fuse with a capped key, so a stolen key has a hard dollar limit.
Does Fuse store my prompts?
No. Requests pass through in memory and are never written to a database or log. Fuse keeps metadata only: time, model, tokens, cost, status.