Nexus Void AI Research

Gemini, API keys, Google Cloud, LLMjacking, secrets management, AI security

Gemini API Key Security in 2026: Restrict, Cap, Rotate

Gemini API key security: why old Google keys could call Gemini, how to restrict and audit keys, cap spend, and respond if a key is stolen.

Gemini API key security comes down to three things: make sure no Google API key in a Gemini-enabled project is unrestricted, keep Gemini keys out of browsers and repos, and put a hard spend limit in place. Budget alerts only notify you. If a key leaks, rotate it, check usage, and contact Cloud Billing support.

Last updated 1 December 2026.

Gemini keys are ordinary Google Cloud API keys, the same AIza strings teams have shipped in front-end code for years for Maps and Firebase. That history is why teams get surprised.

Why are Google API keys a bigger risk once Gemini is enabled?

Google API keys were long treated as public project identifiers, safe to ship in web and mobile code. A key with no API restriction works for every API enabled in its project. So when a team enables the Gemini (Generative Language) API, every old unrestricted key in that project can start calling a paid model.

Firebase still says API keys for Firebase services are OK to include in code. The same page says the key used for the Gemini Developer API should never be in your code or on a public key's allowlist.

In February 2026, researchers at Truffle Security found 2,863 live Google API keys on the public web, including in embedded maps, that could reach Gemini because the Generative Language API had been enabled in the project. The Hacker News reported that new keys defaulted to Unrestricted, with no warning to key owners. Malwarebytes advised auditing every key.

A Google spokesperson said Google had added measures to detect and block leaked keys that try to reach the Gemini API.

Google has since tightened the rules. Its Gemini API key documentation now states:

  • Starting May 7, 2026, the Gemini API blocks unrestricted API keys that have been dormant for an extended period.

  • Starting May 28, 2026, all new API keys created in Google AI Studio are created as auth keys, bound to a service account.

  • The Gemini API rejects requests from unrestricted standard keys. Standard keys with explicit restrictions keep working.

Our read: these rules close the loudest door. They do not help when a key restricted to Gemini leaks through a repo, a log or a laptop. That key still works, and it still bills you.

How do you audit every API key in a Google Cloud project?

List every key, then check two things on each one: which APIs it can call (API restrictions) and where it can be used from (application restrictions). Any key that can reach the Generative Language API and also sits in public code is the one to fix first.

  • List keys with gcloud services api-keys list. Across an organization, Cloud Asset Inventory can list apikeys.googleapis.com/Key assets and filter for keys with no restrictions.

  • Disable the Generative Language API in any project that does not use Gemini.

  • Make sure no Maps or Firebase key has the Generative Language API on its allowlist.

  • Search repos, mobile builds and front-end bundles for AIza strings and match each to a key. Start with the oldest keys.

Google Cloud's API key documentation says unrestricted API keys are insecure and recommends both restriction types. API restrictions decide which services a key can call, no matter who holds it. Application restrictions limit use to websites (HTTP referrers), IP addresses, Android apps or iOS apps, one type per key.

Referrer restrictions are the weak spot. A referrer is a header the caller sends, and a script can send any value it likes. Google itself says bypassing mobile app restrictions is straightforward. Treat application restrictions as a speed bump and API restrictions as the real control. A server-side Gemini key should allow only the Gemini API and only your servers' IP addresses.

Finding keys is the slow part. ARGUS scans every repo for secrets with a gitleaks-based engine, marks each one live, rotated or test, and flags every place your code calls an LLM provider. For the manual route, see finding hardcoded secrets and removing secrets from git history.

Gemini key settings at a glance

Key setting

Risky default

Safe setting

API restrictions

None (key works for every enabled API)

Only the APIs the key needs; Gemini keys limited to the Generative Language API

Application restrictions

None, or HTTP referrer only

IP addresses of your servers for server-side Gemini calls

Where the key lives

Front-end bundle, mobile app or .env in git

Secret manager, read by a backend that proxies calls

Key type

Standard key shared across services

Auth key bound to a service account, or ADC with no key

Project layout

Dev, staging and prod in one project

Separate projects per environment, Gemini enabled only where used

Spend control

Budget alert email only

Gemini usage cap or prepaid credits, plus budget alerts

Rotation

Never rotated

Scheduled rotation and immediate rotation on any exposure

What is the difference between AI Studio keys and Cloud console keys?

Both are Google Cloud API keys tied to a project. The difference is the default. New keys created in Google AI Studio since May 28, 2026 are auth keys, bound to a service account and limited to the Gemini API by default. Keys made in the Cloud console for other services may be standard keys with whatever restrictions someone set.

Google says standard keys do not identify a caller, while auth keys run requests under a service account and support fast-acting leaked key enforcement. Creating a Gemini key in the Cloud console now requires binding it to a service account.

One audit trap: AI Studio only displays keys that are unrestricted or restricted to the Gemini API, up to 100 keys and 50 projects. Audit from the Cloud console or gcloud too. To lock a key down, use Restrict to Gemini API only in AI Studio, or for a shared key, remove the Generative Language API from its allowlist in the Cloud console.

Can budget alerts or quotas stop a surprise Gemini bill?

Budget alerts cannot. Google Cloud's billing docs say an alerts-only budget does not cap usage or spending, and the first alert can take several hours to arrive. To stop spend you need a Gemini API usage cap, prepaid credits, or automation that disables billing when a budget is crossed.

A stolen key runs fast. Google's November 3, 2026 LLMjacking report describes one actor making more than 500,000 LLM API calls in under eight hours, passing nearly $1 million in token costs to the victim.

What each control does, per Google's budget docs, Gemini billing docs and quota docs:

  • Budget alerts email you at 50%, 90% and 100% by default. They stop nothing.

  • Pub/Sub budget notifications can trigger code that disables Cloud Billing on a project. A real stop, but for everything in that project.

  • Gemini API monthly usage caps apply per billing account: $250 for Tier 1, $2,000 for Tier 2, $20,000 to $100,000 for Tier 3. Service then pauses until the 1st of the next month. Per-project caps are experimental and can overshoot.

  • Prepay credits stop all keys on the billing account with HTTP 402 at zero balance, after roughly 10 minutes of billing latency.

  • API quotas cap requests per day or minute. They limit volume, not money.

Separate projects per environment make each control sharper. Give dev, staging and production their own projects, budgets and quotas, and enable Gemini only where it is used. A leaked dev key then hits a small cap in a project with nothing else in it.

Should server-side Gemini calls use service accounts instead of API keys?

For production on Google Cloud, yes where you can. Google's docs for Gemini on Google Cloud (the aiplatform.googleapis.com endpoint, now documented as Gemini Enterprise Agent Platform) say to use an API key for testing and Application Default Credentials for production. ADC uses a service account identity with no long-lived string to leak.

Logging is the other reason. Google's key docs say the Gemini Developer API gives only aggregate usage metrics, with no per-request audit logs or caller IPs. The platform docs recommend ADC when you need per-caller attribution. GTIG notes Data Access audit logs for aiplatform.googleapis.com are off by default, so turn them on.

Service accounts shift risk rather than remove it. GTIG found exposed cloud credentials, including service account keys, were the main way attackers got in. Prefer attached service accounts or workload identity over downloaded JSON keys.

Never call Gemini from a browser or mobile app with a raw key. Google says to use a backend proxy instead. See our guides on securing a Next.js app, securing Firebase and AI gateway security.

What should you do if your Gemini API key was stolen?

Replace the key, deploy the new one, then disable the old key and review usage and billing for unauthorized activity. Then find out how it leaked, because a new key in the same leaky place gets stolen again. If you were charged for usage you did not make, contact Cloud Billing support, with no guarantee of a credit.

Keys stored in Google Secret Manager get stolen too. When that happens the vault is usually fine; something that reads from it is not. See API key leaked from Secret Manager and what is LLMjacking.

  • Rotate in Google's order. Create a replacement key, deploy it, then disable the old one. Don't delete it until the new key is fully active.

  • Check usage. Use AI Studio's Dashboard, Usage view and the API's quota page in the Cloud console. Look for models and volumes you don't use.

  • Re-list keys and enabled APIs. GTIG saw attackers enable new LLM services and mint their own keys.

  • Set a hard limit now on the affected project before you finish investigating.

  • Contact billing support. Google gives all Cloud accounts free billing support. A Billing Account Administrator opens it from Help and support, choosing Billing, then Get billing support. Non-admins can use Google's Support Contact Troubleshooter.

  • Find the leak path: repos, CI logs, front-end bundles, laptops, and any identity that can read the secret.

Be realistic about money. Google's billing support page does not promise credits for unauthorized usage, and prepay Gemini accounts are not refundable except when switching account types. Save timestamps and usage graphs before opening the case. Our leaked API key checklist, API key storage guide and the OWASP Secrets Management Cheat Sheet cover the longer fix.

Dealing with a stolen key right now? Work through our LLM API key compromised checklist step by step.

Frequently asked questions

Is a Google Maps API key a secret?

It used to be treated as a public identifier. But if the Gemini API is enabled in the same project and the key has no API restriction, that key can call Gemini. Treat any key in a Gemini-enabled project as a secret.

Can a stolen Gemini API key run up a bill?

Yes. Gemini usage on a paid project is billed to the project that owns the key. Google's threat intelligence team reported LLMjacking incidents where fraudulent charges passed $100,000 in a single day. Spend caps and prepaid credits limit how far a stolen key can go.

Do budget alerts stop Gemini charges?

No. Google Cloud's docs say an alerts-only budget does not cap usage or spending. Alerts can also arrive hours late. To stop spend automatically you need a Gemini API usage cap, prepaid credits, or a Pub/Sub budget notification that disables billing on the project.

How do I restrict a Gemini API key?

In Google AI Studio, choose Restrict to Gemini API only for a key that should only call Gemini. For a key shared with Maps or other services, edit it in the Cloud console and allow only the APIs it needs, leaving out the Generative Language API.

What is the difference between an AI Studio key and a Cloud console key?

Both are Google Cloud API keys. Since May 28, 2026, new AI Studio keys are auth keys bound to a service account and limited to the Gemini API by default. AI Studio hides keys with other restrictions, so audit in the Cloud console too.

Will Google refund charges from a stolen Gemini key?

There is no guaranteed refund. Contact Cloud Billing support from the Google Cloud console as a Billing Account Administrator and explain the unauthorized usage. Google's Gemini billing docs say prepay accounts are not refundable except when switching account types, so check your plan first.

Should I call Gemini from the browser or a mobile app?

No. Google's docs say not to hardcode keys in web or mobile apps and to route calls through a backend. For production on Google Cloud, Google recommends Application Default Credentials over API keys.

ARGUS scans every repo for secrets and tells you which are live, maps where your code calls LLM providers, and can block risky pull requests at merge. It does not watch your Gemini bill, so keep the caps above. Free plan available; Pro is $49/month and Team $199/month with unlimited seats. Start a free scan.

DATA SOURCES

Google AI Studio, Gemini API keys: https://aistudio.google.com/docs/api-key; Google AI Studio, Gemini API billing: https://aistudio.google.com/docs/billing; Google Cloud, Manage API keys: https://docs.cloud.google.com/docs/authentication/api-keys; Google Cloud, Create budgets: https://docs.cloud.google.com/billing/docs/how-to/budgets; Google Cloud, Capping API usage: https://docs.cloud.google.com/apis/docs/capping-api-usage; Google Cloud, Cloud Billing support: https://docs.cloud.google.com/support/docs/get-billing-support; Google Cloud, Gemini Enterprise Agent Platform API keys: https://docs.cloud.google.com/gemini-enterprise-agent-platform/models/start/api-keys; Firebase, API keys: https://firebase.google.com/docs/projects/api-keys; Google Threat Intelligence Group, LLMjacking (3 Nov 2026): https://cloud.google.com/blog/topics/threat-intelligence/llmjacking-monetizing-compromised-cloud-models; The Hacker News (28 Feb 2026): https://thehackernews.com/2026/02/thousands-of-public-google-cloud-api.html; Malwarebytes (27 Feb 2026): https://www.malwarebytes.com/blog/news/2026/02/public-google-api-keys-can-be-used-to-expose-gemini-ai-data; OWASP Secrets Management Cheat Sheet: https://cheatsheetseries.owasp.org/cheatsheets/Secrets_Management_Cheat_Sheet.html

Liked this post? Share it:

Related posts