GrepBoard/Manuals
605 manuals ·

Fix Gemini API 403 "Your API key was reported as leaked"

·Tested on Gemini API official docs · 2026-10·Test scope ↓·7 steps

When the Gemini API returns 403 "reported as leaked", find the blocked key in AI Studio, switch to a new one, then take keys out of code and repositories.

text
Your API key was reported as leaked. Please use another API key.

This message comes back as HTTP 403 PERMISSION_DENIED. The official troubleshooting page files it under "Blocked or non-working API keys" and explains that Google found some API keys publicly exposed and blocked them to protect your data and prevent unauthorized access. The key itself is blocked, so changing the request or retrying will not help. It is not a rate-limit error either (see Retry Gemini API 429 and 503 Errors with Backoff).

[1] Tell this apart from other 403s. The page's "Project restricted or unavailable" section covers a 403 PERMISSION_DENIED that arrives as "Your project has been denied access".

MessageCause the docs point toDocs action
Your API key was reported as leaked. ...The key was exposed and blockedGenerate a new key
Your project has been denied accessFree tier not available, billing account past due, or the project or billing account suspended for a policy violationCheck billing, link the paid tier, read the suspension guidance

This article covers the first row only. In the second row, the sentence "creating a new key in the same project won't fix it" belongs to the free-tier-unavailable case, not to leaked-key blocks.

[2] Find out which key is blocked. The docs say you can use Google AI Studio to see which of your keys are blocked. The key management screen is the API Keys page, though the docs link that address as the place to create new keys, so they do not by themselves confirm that the blocked marker appears there. Match the key that failed against your key list in AI Studio. How a blocked key is displayed there is not described in the docs.

[3] Create a new key and replace it. The docs' action is to "generate new API keys for your Gemini API integrations using Google AI Studio". Replace the key everywhere it is used: server environment variables, secret stores, CI. If even one place keeps the old key, the same 403 continues. The official quickstart shows the key in a GEMINI_API_KEY environment variable, sent in an x-goog-api-key request header.

console
$ export GEMINI_API_KEY="YOUR_API_KEY"

[4] Delete or restrict the old key. What the docs say is that you "can no longer use that key with the Gemini API". Whether a leaked key still works against other APIs enabled in the same Google Cloud project is not stated in the docs consulted. So after every app is on the new key, delete the old one. Google Cloud's API key management docs describe rotation as: create the new key, switch all applications to it, then delete the old key (on the Credentials page in the console), and say a key deleted by mistake can be restored within 30 days. If you need to be sure nothing still uses it before deleting, first add an API restriction to narrow what the key can call; the same page notes that a key without application restrictions can be used from anywhere. How to find which Google Cloud project an AI Studio key belongs to on screen was not confirmed here.

[5] Find where the key leaked and remove it. The docs say "Never embed API keys directly in client-side code or public repositories". Places to check:

  • Source, config files, and notebooks in public repositories
  • Client code shipped to browsers or mobile apps
  • Request logs pasted into issues, forum questions, or screenshots

How to scrub a published key from repository history is not covered by the source docs, so it is not covered here. The point is not to put the new key back in the same place, and to delete the old key as in step [4].

[6] If you saw unexpected charges, open a billing support case. That is the route the docs give. Whether charges are adjusted is not stated in the docs.

[7] Verify with the new key. If the new key returns the same message, check whether it is the other 403 from step [1] and whether the new key is also somewhere public. Note that the docs say a read-only call such as models.list only checks that the key exists, so a 200 does not prove inference is enabled. Do not judge the key healthy from a list call; test with a real generation call.

Check it with the HTTP status codes tool ↗ — calculated in your browser.

#gemini#api#403#api-key