Skip to content

Security and governanceGuide

Google API keys and Gemini: how embeddable keys got exposed

For years Google told developers that some API keys could sit in a web page. Then enabling Gemini on a project quietly gave those keys a new power. Here is what the 2026 research found, what Google's documentation now says, and the fix: restrict, separate and prefer identity.

By INFRO Editorial

Published

8 min read

A grid of dark glass cards with small bar charts, a few of them lit amber, on a dark ground

In short

Google API keys (the AIza… format) were designed to be embedded in client code for services like Maps. In February 2026 Truffle Security showed that enabling the Generative Language (Gemini) API on a project let existing unrestricted keys in that project call Gemini, and found 2,863 live keys exposed on the public web that could. Google's documentation now says the Gemini API rejects unrestricted standard keys and blocks long-dormant ones. Still: restrict every key to the APIs and callers it needs, keep Gemini in its own project, disable unused APIs, and prefer service accounts or Vertex AI with IAM.

Key takeaways

  • A standard Google API key identifies a project, not a caller; it can call any enabled API that accepts keys unless it is restricted.
  • Truffle Security showed in February 2026 that enabling Gemini on a project let existing embeddable keys call Gemini, and found 2,863 live keys on the public web that could.
  • Google's Gemini key page now says the Gemini API rejects unrestricted standard keys and, since 7 May 2026, blocks long-dormant unrestricted keys; restricted keys that include Gemini still work.
  • Restrict every key by API and by application, keep Gemini in its own project, and disable APIs you do not use.
  • Budgets in Google Cloud alert but do not stop spend; Gemini project spend caps are experimental and can overshoot.

Can a Google API key expose Gemini? Yes, if it is allowed to call the Generative Language API. Google API keys in the AIza… format were designed so that some of them, such as Maps keys, could sit in a web page. A standard key identifies a project, not a caller, and can call any enabled API that accepts keys unless it is restricted. In February 2026 Truffle Security showed that enabling the Gemini API on a project silently gave the existing keys in that project access to it, and found 2,863 live keys on the public web that could call Gemini1.

Google has changed its defaults since. This guide sets out what the research found, what Google's documentation says today, and the fix, which is the same whatever the defaults: restrict every key, keep Gemini in its own project, and prefer identity over keys.

Why a public key became a Gemini key

Google's own definition explains the exposure. A standard API key associates a request with a project "for billing and quota purposes"; it does not identify a principal, so IAM cannot check whether the caller is allowed to make the request. A standard key can be used with any API that accepts API keys "unless API restrictions have been added to the key"2.

For a Maps key in a web page, that was acceptable: the worst a stranger could do was load maps on your quota. Truffle's finding was that the set of APIs a key could reach was not fixed. Enabling the Generative Language API on a project gave existing keys in it access to Gemini endpoints, with no warning, and new keys defaulted to unrestricted, so they worked with every enabled API including Gemini1.

What the key was created forWhat it could do after Gemini was enabled
Load maps or another client-side API, on the project's quotaCall Gemini models billed to the project
Nothing secret; embedded in public JavaScriptReach files and cached content through Gemini's /files/ and /cachedContents/ endpoints
Visible to every visitorExhaust the project's Gemini quota for its legitimate users

The right column is Truffle's list of what an attacker with one valid key could do1.

What the research found

Truffle scanned the November 2025 Common Crawl and found 2,863 live keys vulnerable to the escalation, belonging to organizations it described as including financial institutions, security companies, recruiting firms and Google itself. Its disclosure timeline, as Truffle tells it1:

  • 21 November 2025: reported through Google's vulnerability disclosure program.
  • 25 November: Google initially said the behaviour was intended.
  • 2 December: reclassified as a bug with upgraded severity.
  • 12 December: Google shared a remediation plan, including restricting exposed keys from Gemini.
  • 2 February 2026: the root-cause fix was still in progress; the 90-day window closed on 19 February.

Truffle reports that Google's published roadmap included Gemini-only defaults for new AI Studio keys, blocking of leaked keys and proactive notification, and that it had not yet seen a root-cause outcome when it published.

The cost of a key in the wrong hands is not theoretical. In July 2026 The Register reported a developer whose Google Cloud account recorded $11,089.77 over two days, mostly on Gemini image models; Google suspended the account for "abusive activity consistent with hijacked resources", attributed the root cause to a compromised Firebase service account key, and the developer said Google's billing team had refused to waive the charges3. That case was a service account key, not an embedded API key, which is the point: any credential that can reach Gemini is a billing credential.

What Google's documentation says now

Google's Gemini API key page, last updated in October 2026, describes a move from standard keys to authorization ("auth") keys, which are bound to a service account so that requests run under that account's identity4. It states:

  • "The Gemini API rejects requests from unrestricted standard keys." The page gives no date for this change. Standard keys with explicit restrictions continue to work.
  • Since 7 May 2026, the Gemini API blocks unrestricted keys that have been dormant for an extended period; they show a Blocked tag in AI Studio.
  • Since 28 May 2026, new keys created in Google AI Studio are auth keys by default, restricted to the Gemini API.
  • Auth keys get "fast-acting leaked key enforcement" for leaks Google's systems detect.

Google Cloud's general documentation adds that "Unrestricted API keys are insecure", that the console and gcloud require at least one API restriction when you create a key, and that a key created through the REST API is unrestricted unless you add restrictions2.

These changes close the original path for an unrestricted Maps key. They do not cover a key whose API restrictions include the Generative Language API alongside Maps, a Gemini key deliberately shipped in client code, or a key created through the API without restrictions. Check your keys rather than relying on the default.

The fix

1. Find every project where Gemini is enabled

Projects and keys that can reach Gemini
gcloud services list --enabled --project="$PROJECT" | grep generativelanguage
gcloud services api-keys list --project="$PROJECT"
gcloud services api-keys describe "$KEY_ID" --project="$PROJECT"

Truffle's checklist starts the same way: look for the Generative Language API under Enabled APIs & Services, then review keys that are unrestricted or explicitly allow it, oldest first, and confirm none of them are public1.

2. Restrict every key twice

Google recommends "both API restrictions and application restrictions"2:

  • API restrictions list the services a key may call. A Maps key should list Maps APIs and nothing else; gcloud services api-keys update KEY_ID --api-target=service=SERVICE replaces the whole list, so name every service the key needs.
  • Application restrictions say who may use the key: websites (HTTP referrers), IP addresses, Android apps or iOS apps. A key can carry one type. A server-side Gemini key should be limited to your egress addresses with --allowed-ips.

Keep in mind what a referrer restriction is: a header a browser sends, which a script outside a browser can set to anything. It narrows casual abuse of a key that has to be public; it does not make a powerful key safe to publish. A key that can reach Gemini should never be in client code. Google's guidance is to run a backend proxy for client apps and not to hardcode keys in web or mobile apps4; AI API keys in frontend and mobile apps covers the patterns.

3. Keep Gemini in its own project

Put Gemini traffic in a project that holds no client-side keys, and keep browser and mobile keys in projects where the Generative Language API is not enabled. A key cannot call an API its project has not enabled. Disable APIs a project no longer uses (gcloud services disable generativelanguage.googleapis.com) so that a forgotten key has less to reach.

4. Prefer identity over keys

A standard key cannot be checked by IAM; a service account can. Where you can, call Gemini through Vertex AI with a service account and IAM roles, or use auth keys bound to a service account through the Gemini API4. Google Cloud cautions against auth keys in production for APIs that create or manage Google Cloud resources2, and a service account's own key file is still a long-lived secret, as The Register's case shows. Workload identity, where the platform issues short-lived tokens, removes the file.

5. Put a ceiling on the project

Know what each billing control does before you rely on it:

ControlWhat it doesLimit
Cloud Billing budgetAlerts at thresholdsDoesn't "automatically cap Google Cloud or Google Maps Platform usage or spending"5
Budget notification that disables billingStops billing on the project programmaticallyStops every paid service on the project; Google warns resources "might be irretrievably deleted"3
Gemini project spend cap (AI Studio)Monthly cap per projectExperimental; billing data can lag around 10 minutes and overages are possible6
Gemini billing-account tier capPauses Gemini for all linked projects at the tier limitAccount-wide, not a per-key limit6

If a key has already leaked

Google's leak checklist: generate a replacement, deploy it, disable the compromised key once the new one is verified, and audit billing and API usage in the Cloud console4. Two additions:

  • Deleting is not instantly final. A deleted key can be undeleted within 30 days2. If someone else may hold project permissions, check that nobody restores it.
  • Report the usage. Google's billing documentation says to secure the account, stop resources you do not recognise, and contact Cloud Customer Care to discuss billing adjustments, which it reviews "on an individual basis"7. Stolen API key charges covers what the terms say.

GitHub's secret scanning reports Google API keys to Google as a partner pattern, but its separate Gemini API key pattern is user-alert only, and neither Google pattern is blocked by push protection8. Turn on push protection and run a scanner of your own.

How INFRO handles Google keys

INFRO runs on provider accounts you connect, including Google's. A Gemini credential you connect is sealed with AES-256-GCM and never shown again (see Connect a provider), so it does not need to live in client code or in each service. Your applications call INFRO with gateway keys that can be limited to chosen providers and IP ranges, belong to one environment, expire, and are capped by budgets checked before Google is called.

INFRO's controls govern traffic that goes through INFRO. A Google key or service account credential leaked from anywhere, including from a platform like INFRO that holds it, can be used directly against Google, and no INFRO budget or allowlist sees it. The restrictions, project separation and billing controls in this guide are the backstop, and they live in your Google Cloud project.

Summary

A Google API key is a project's billing handle, not an identity, and it can call whatever its project has enabled unless you restrict it. Gemini turned that from a quota concern into a cost and data concern. Google now rejects unrestricted standard keys on the Gemini API, but restricted keys that include Gemini still work. Restrict every key by API and by caller, keep Gemini in a project with no public keys, disable what you do not use, and move server traffic to service accounts and IAM.

Questions readers ask

Can a Google Maps API key call Gemini?
It could. Truffle Security showed that enabling the Generative Language API on a project let existing unrestricted keys in that project call Gemini. Google's Gemini key documentation now says the Gemini API rejects unrestricted standard keys, but a key whose API restrictions include the Generative Language API still works, so check each key's restrictions.
Are Google API keys secret?
Some were designed not to be: Google documented that keys for services like Maps could be embedded in client code. A standard key identifies a project for billing and quota, not a caller, so whatever APIs it is allowed to call, anyone holding it can call. Treat any key that can reach Gemini as a secret.
How do I restrict a Google API key?
Add API restrictions (the services the key may call) and one application restriction (websites, IP addresses, Android apps or iOS apps). Google says unrestricted API keys are insecure and recommends both. With gcloud, use gcloud services api-keys update with --api-target and, for example, --allowed-referrers or --allowed-ips.
What should I do if my Gemini API key leaked?
Google's checklist: create a replacement key, deploy it, disable the leaked key once the new one works, and audit billing and API usage in the Cloud console. If the usage is not yours, report it to Cloud Customer Care; Google says it reviews billing adjustments case by case.

From the team that builds it

Where this shows up in INFRO

INFRO is a control plane in front of the provider accounts you already hold. The capabilities below are the parts of it this article touches, each with the documentation that defines its behaviour.

  • Provider connections

    Available with a plan

    Connect provider accounts you already hold. Each credential is encrypted when saved, scoped to your organization and never shown again; applications use INFRO gateway keys instead.

    Read the documentation for Provider connections
  • Key limits and rotation

    Available with a plan

    Limit a gateway key to chosen providers or IP ranges, and rotate it with an overlap window so the old key keeps working while you deploy the new one.

    Read the documentation for Key limits and rotation
  • Budgets and spend ceilings

    Available with a plan

    A hard cap per organization, project, member, and key, with alerts at your own thresholds.

    Read the documentation for Budgets and spend ceilings
  • Environments

    Available with a plan

    Production, staging and development to start, and your own beside them. A connection or route serves one, several or every environment; each gateway key belongs to exactly one, and never reaches a connection outside it.

    Read the documentation for Environments
  • Spend anomaly and drift alerts

    Available with a plan

    Each scope's usual day is learned from its own history; a day that departs from it, a budget forecast to be exceeded, cost estimates drifting from the provider's own figures, unpriced traffic and failing connections become findings in the console. Routed to email on every plan, and to Slack and signed webhooks from the Startup plan.

    Read the documentation for Spend anomaly and drift alerts

INFRO accounts are self-serve. Provider usage is billed to you by your providers; INFRO charges a software subscription and takes 0% of model spend. See plans.

Sources

Numbered in order of first citation. Each was opened and checked against the claim on the date shown.

  1. 1.Google API Keys Weren't Secrets. But then Gemini Changed the Rules. (opens in a new tab) — Truffle Security. Accessed Oct 21, 2026.
  2. 2.Manage API keys (opens in a new tab) — Google Cloud. Accessed Oct 21, 2026.
  3. 3.Dev says Google warned him about account hijack – then charged him $11,000 anyway (opens in a new tab) — The Register. Accessed Oct 21, 2026.
  4. 4.Using Gemini API keys (opens in a new tab) — Google AI for Developers. Accessed Oct 21, 2026.
  5. 5.Create, edit, or delete budgets and budget alerts (opens in a new tab) — Google Cloud. Accessed Oct 21, 2026.
  6. 6.Billing (Gemini API) (opens in a new tab) — Google AI for Developers. Accessed Oct 21, 2026.
  7. 7.Resolve Cloud Billing issues (opens in a new tab) — Google Cloud. Accessed Oct 21, 2026.
  8. 8.Supported secret scanning patterns (opens in a new tab) — GitHub. Accessed Oct 21, 2026.

About this article

Truffle Security's research post, Google's Gemini API key and billing documentation, Google Cloud's API key, budget and billing-issue documentation, GitHub's secret scanning pattern list and The Register's July 2026 report were opened on 2026-10-21. The post states only what those sources say; where Google's documentation gives no date for a change, the post says so. Written by the team that builds INFRO.

Last checked against its sources on . The next review is due by . No separate named reviewer is recorded for this article.

How articles are written, sourced and corrected is set out in the editorial standards.