Skip to content
Putting technology to work.
Insights to guide decisions and action.

Search articles

Removing Gemini API keys from production: steps to migrate to ADC

Table of contents · 9 items

When prototyping internal tools or chatbots with Gemini, the quickest approach is to issue an API key in Google AI Studio, paste it into .env and make calls. When that prototype goes into production, the key moves along with it. The guide described below depicts a situation where, by then, each developer has their own key, scattered across .env, shell configuration and chats.

On November 21, the official Google Cloud blog published a guide for getting out of this situation, "Ultimate guide for fixing your team’s API keys." Its approach is that people call Gemini with their own login, apps call it with a service account, and any remaining keys are moved to Secret Manager.

In this article, we organize the guide's five steps in the order you migrate. We also present the results of testing the switchover in the Google Gen AI SDK (Python) in a test environment, the AI Studio key types that changed in May 2026, points where the guide disagrees with other official announcements, and how to find keys in your repositories.

What is wrong with keys

The guide calls AI Studio keys "bearer tokens" and says anyone who has one can use it. According to the guide, keys do not expire automatically and are not tied to any device, person or process. Unless you set a cap, there is no limit on how much can be spent. When an employee leaves, you also cannot tell which keys to disable.

The guide recommends migrating quickly if any of the following apply.

  • A key has left your local machine (shared in chat, committed to a repository, or placed on a server)
  • Multiple people on your team call the API
  • You spend more than a few hundred dollars a month, or you are about to take on paying customers

As a hypothetical example, the guide also describes a scenario in which a key that ends up in a public repository or app is found by automated harvesting within minutes, and the owner pays for whatever is used. We covered real examples of damage from stolen keys and how to detect it in our article on LLMjacking.

AI Studio key types have changed since May

The guide does not mention it, but according to the Gemini API documentation (the API keys page), Gemini API keys are moving from "standard API keys" to "auth keys."

  • Since May 28, 2026, all new keys created in AI Studio are auth keys. An auth key is tied to a Google Cloud service account, and requests are processed as that service account. The documentation says auth keys are restricted to the Gemini API by default, and that there is a mechanism for quickly disabling keys that Google detects as leaked.
  • The Gemini API rejects requests made with unrestricted standard keys. Standard keys with API restrictions can still be used. The documentation does not say on what date the rejections began.
  • Since May 7, 2026, unrestricted keys that have gone unused for a long time are blocked and shown as "Blocked" in AI Studio.

Therefore, for keys created on or after May 28, the guide's statement that keys are "not tied to any process" does not match the documentation. However, anyone who has the key string can still use an auth key. The Google Cloud API keys documentation describes auth keys as "similar to a long-lived access token." The Gemini Enterprise Agent Platform API keys documentation also recommends ADC for production, and says to use ADC when you want audit logs to distinguish each caller. The problem of carrying keys around remains even with auth keys.

Before you start migrating, it helps to check the "Key Type" column (Standard or auth key) and any keys marked "Unrestricted" in the AI Studio API key list, so you can see which keys are still active (editorial suggestion).

The guide's five steps

Diagram of migrating away from Gemini API keys. Developers call the API with their own gcloud login, and roles/aiplatform.user is granted to a group. Apps call it on Cloud Run and similar services with short-lived service account tokens. Keys for external services such as payments and chat are stored in Secret Manager. Finally, the AI Studio API keys are deleted

1. Log in per person. Each person runs gcloud auth application-default login. When you log in to your company account in the browser, gcloud saves short-lived credentials on your machine, and the Google Cloud SDKs find them automatically (ADC, Application Default Credentials). There is no key to copy.

2. Call models with the same login. The guide says that in the Google Gen AI SDK, all you need to do is change a client you created with api_key=... as follows.

from google import genai

client = genai.Client(enterprise=True, project="my-project-dev", location="global")

enterprise=True specifies sending requests to Google Cloud's Gemini Enterprise Agent Platform (formerly Vertex AI) rather than AI Studio (the Gemini Developer API). The guide calls this destination "Gemini Platform," and on November 23 the SDK's README also changed its wording to "Gemini platform (formerly Gemini Enterprise Agent Platform and Vertex AI)." As of November 30, the title of the Google Cloud documentation is still Gemini Enterprise Agent Platform. Older examples use vertexai=True, and the current SDK is said to accept both. The guide says the same login can also call Claude in Model Garden (AnthropicVertex in Anthropic's SDK) and open models. Partner models such as Claude must be enabled once per project in Model Garden. We covered the differences between offerings when using Claude on Google Cloud in our article on Claude on Google Cloud.

3. Attach a service account to the app. On Cloud Run, GKE and Compute Engine, ADC automatically uses short-lived tokens (usually about one hour, according to the guide) for the service account attached to the workload. The code from step 2 does not need to change. The guide also recommends separating the projects developers use from the production project.

4. Grant only the permissions you need. If you only call models, the single role roles/aiplatform.user is enough, and for people, grant it to a Google group rather than to individuals. When someone leaves, removing them from the group removes all their permissions. The guide also lists ways to restrict the models that can be used with vertexai.allowedModels in organization policy, and to block the creation of new API keys (denying creation of apikeys.googleapis.com/Key) and service account keys (iam.managed.disableServiceAccountKeyCreation).

5. Move remaining keys to Secret Manager. Keys you cannot get rid of, such as those for payment or chat services, are stored in Secret Manager, and you decide which people and service accounts can read each one. Finally, delete every AI Studio key that has ever left a local machine. The guide notes that "even after you migrate, a key stays valid until you delete it."

What we confirmed with the SDK

We tested the switchover in step 2 with Google Gen AI SDK (Python) 3.6.1. genai.Client accepts both the enterprise and vertexai arguments, and whichever one we used, the destination was https://aiplatform.googleapis.com/. If you pass no arguments at all, it stops with "No API key was provided." We tested only up to creating the client, in an environment without credentials. We did not call any models.

Because the switchover changes the destination, the available model names, pricing and data handling terms are not necessarily the same as with AI Studio. The SDK changelog also notes that while the default API version for the Gemini Developer API changed to v1, the enterprise=True (vertexai=True) client remains on v1beta1. Before migrating, check whether the models you use are available under the same names on Gemini Enterprise Agent Platform (editorial suggestion).

Where the guide and announcements disagree

In the later part of the steps, the guide describes spend cap budgets as "currently in Preview." This feature stops new requests per service and per project when estimated spending exceeds the cap. However, the official Google Cloud blog announced general availability (GA) on October 30, stating that "spend caps on Google Cloud Budgets are generally available." We summarized what GA added and what gets stopped in our article on spend caps. The spend cap documentation (updated November 10) also does not describe the feature as Preview, and lists the Gemini API and Gemini Enterprise Agent Platform among the supported services. The November 21 guide was published later, but it is reasonable to judge the release stage by the GA announcement and the documentation (editorial judgment). The guide's explanation that the cap "is judged on estimated costs and stays in effect until the start of the next month or until lifted" matches the GA announcement's mention of "estimated, live costs" and automatic lifting at the start of the month.

Finding keys in your repositories

The repository that accompanies the guide includes a script for finding keys. Reading the code, it looks for strings that start with AIza followed by 35 alphanumeric characters, _ or -, as the format of Google API keys. The results show only the file and line, not the key itself (we did not run this script). The Google Cloud API keys documentation also gives a string starting with AIza that fits this format as an example of a key string. We have not confirmed whether real auth keys have the same format.

You can also search for strings of the same format using git alone. Keys that are no longer in the current files can still be retrieved if they remain in past commits, so check the history as well.

# 今のファイル
git grep -nE 'AIza[0-9A-Za-z_-]{35}'
# 過去のコミットも含める
git log -p --all -G 'AIza[0-9A-Za-z_-]{35}' --format='%h %an %ad %s'

When we tested this on a repository where a fictitious key was added in the first commit and removed in the second, the first expression returned nothing, while the second returned both commits and the line with the key. Even if you remove it from the history, a key that has been pushed once remains in other clones, so any key you find should be deleted and reissued (editorial team's analysis).

Order of steps for small and mid-sized development (editorial suggestion)

  1. Count your keys. Using the expressions above and the AI Studio key list, make a list of which keys were created by whom and where they are, including each key's type and whether it is restricted
  2. Switch developers over first. Once you set up a development project and group, you can carry out steps 1 and 2 without touching production
  3. Switch over production apps. Attach a service account, confirm that the app works with the code from step 2, and then delete the production keys
  4. Decide on caps and notifications. If you use spend caps, agree with the people in charge on what will happen to operations when requests are stopped

For taking internal tools that use Gemini into production, or designing Google Cloud permissions, please contact us through consultation on development, AI, and automation.

Scope of verification

On November 29, 2026, we read "Ultimate guide for fixing your team’s API keys" (November 21) on the official Google Cloud blog, and the README and step1_keyless_auth code of the accompanying repository sergiov8/secure-your-keys-demo (commit 86ad64c, October 27, 2026) (document research). On the same day, we installed google-genai 3.6.1 on Python 3.11.18, checked the arguments and destination of Client, and tested the key-search expressions on a fictitious key with git 2.43.0 (hands-on testing; scripts and output are saved in the article's evidence records). We did not run the code in the accompanying repository. On November 30, 2026, we read the Gemini API documentation (the API keys page and release notes) and the Google Cloud documentation (API keys, Gemini Enterprise Agent Platform API keys, spend caps, organization policy and Agent Platform roles), and confirmed on PyPI that the latest version of google-genai is still 3.6.1. We did not test calls in an actual Google Cloud project, the AI Studio key management screen, creating auth keys, organization policy, Secret Manager or spend caps.

References

Share this articleXFacebook
Kakeru Suzuki

Fascinated by the possibilities of technology, has had a deep interest in programming and digital art since student days

Turn this article's theme into your company's next step

Concrete steps forward for your organization.

We organize your desired architecture, legacy systems, and operational requirements to formulate your next steps toward execution.

  • Desired architecture
  • Integration with existing environments
  • Operational requirements
Consult on development & operations initiatives

You can consult with us from the initial conceptual stage. Details from this article will be carried over to the inquiry form.

Receive the latest articles by email