Gemini API errors

Gemini says my API key was reported as leaked: what do I do?

"Your API key was reported as leaked. Please use another API key." means Google knows the key leaked and has blocked it from the Gemini API, and it won't work with Gemini again. The fix is a new key: create one on the API Keys page in Google AI Studio, deploy it, then check your usage and billing for calls you don't recognize.

The error comes back as 403 PERMISSION_DENIED, so retrying won't help. Since May 7, 2026, Google also blocks unrestricted keys that sat unused for a long time; those show a Blocked tag in AI Studio and need the same fix.

Replace the key

  1. Create a new key on the API Keys page in AI Studio. Since May 28, 2026, every new key made there is an auth key, which is restricted to the Gemini API by default.
  2. Deploy the new key. Read it from an environment variable or a secret store like Google Cloud Secret Manager, never from code in Git or in a web or mobile app.
  3. Disable the old key in the Google Cloud console once the new one works, and delete it when nothing depends on it.
  4. Audit usage: check billing and API usage in the Google Cloud console for activity you don't recognize.

In the Cloud console you can also rotate a key instead: on the Credentials page, open the key, click Rotate key, confirm the restrictions, click Create, update your apps, then click Delete the previous key. A key deleted by mistake can be restored within 30 days.

Check what the leak cost

  • AI Studio, Dashboard, Usage: your Gemini API usage.
  • AI Studio Billing page: your balance and due dates. AI Studio's billing data can lag up to about 10 minutes.
  • Cloud Billing Reports in the Google Cloud console: costs per project and service. Google says cost details usually show up within a day, sometimes after more than 24 hours.
  • Logs Explorer: Google's advice after any compromised credential is to review audit logs for API calls made during the incident window.
  • Unexpected charges: Google's troubleshooting page says to submit a billing support case from the Google Cloud console.

What limits a leaked key's spend

A leaked Gemini key can spend until one of Google's limits stops it. Which ones apply depends on your billing plan and tier; the details are in how to limit Gemini API spend.

LimitSizeWhat happens when it's reached
Prepay credit balanceWhatever credit you boughtRequests stop when the balance runs out; processing delays can leave a negative balance
Spend-based rate limit$10 per rolling 10 minutes on Tier 1, $200 on Tiers 2 and 3, where it appliesRequests fail with 429 RESOURCE_EXHAUSTED
Billing tier spend cap$250 on Tier 1, $2,000 on Tier 2, $20,000 to $100,000 on Tier 3Service pauses for every project on the billing account until the 1st of the next month
Your project spend capThe monthly amount you set in AI StudioGoogle marks it experimental: spend can run over for about 10 minutes

Lock down the new key

  • Restrict it to the Gemini API. On the API Keys page in AI Studio, find keys labeled Unrestricted, click Add restrictions, pick Restrict to Gemini API only and click Restrict key. You need the apikeys.keys.update permission, which comes with API Keys Admin or Editor.
  • Add an application restriction. On the Cloud console credentials page, open the key and set Application restrictions, for example to your server's IP addresses.
  • Keep it off the client. Google warns that keys in web or mobile apps can be extracted. Call Gemini from a backend instead.
  • Watch the bill. Google's own advice is to set billing alerts in the Google Cloud console for spikes in usage or cost.

Google also rejects Gemini requests from unrestricted standard keys, so an old key without restrictions stops working even if it never leaked.

Where Costbrake fits

Costbrake reads Gemini spend from Google Cloud with read-only access. Live estimates from Cloud Monitoring run about 5 minutes behind and are checked every 5 minutes on Pro and Team, every 2 minutes during a spike, so a leaked key burning tokens shows up as a spike alert by email, Slack, Discord or webhook. The Cloud Billing export, usually a few hours behind, fills in the final numbers.

When you connect Google Cloud, Costbrake lists the API keys in up to 6 projects that have the Gemini API on, never the key strings, and warns about keys with no restrictions or no application restriction. If spend keeps climbing, an admin can confirm a brake that sets a zero Google spend cap on the Gemini API in one project. That stops your own app too, it isn't instant, and usage until Google acts is still billed.

Costbrake can't rotate, disable or delete keys, and it can't get charges refunded; that's done in Google AI Studio, the Cloud console and a billing support case. Plans are on the pricing page, setup is on the Google Cloud integration page, and the first-hour steps for any provider are in what to do in the first hour after a key leaks.

Questions and answers

Can I unblock a Gemini API key that was reported as leaked?

No. Google says that if your key is known to be leaked, you can no longer use it with the Gemini API. Create a new key in Google AI Studio, deploy it, and disable the old key in the Google Cloud console.

Why was my Gemini API key blocked if I never posted it anywhere?

Google blocks keys it has identified as publicly exposed, and keys in web or mobile apps can be extracted by anyone who uses the app. Since May 7, 2026, Google also blocks unrestricted keys that sat unused for a long time. AI Studio shows which of your keys are blocked.

Do I have to pay for usage from a leaked Gemini API key?

Google's troubleshooting page says to submit a billing support case for unexpected charges from leaked keys. Note the dates and the usage you don't recognize from AI Studio and Cloud Billing Reports before you open the case.

How do I stop a new Gemini API key from leaking?

Keep it on a server, read it from an environment variable or Secret Manager, and never commit it to Git or ship it in a web or mobile app. Restrict it to the Gemini API, add an IP or app restriction, and set billing alerts so abuse shows up fast.

Does Costbrake detect leaked Gemini API keys?

Not the leak itself. Costbrake watches Gemini spend and alerts on spikes within minutes on Pro and Team, and when you connect Google Cloud it flags keys with no restrictions. An admin can then confirm a zero spend cap on the Gemini API in one project. Rotating the key is still done in Google AI Studio.

Sources

Updated