Google Cloud Pushes Teams Off Raw Gemini API Keys Toward Identity-Based Access
Google Cloud published a five-step guide for moving AI prototypes off shared Gemini API keys and onto user logins and service accounts. It also describes spend caps that pause a service once a budget is reached.
TL;DR
- Google Cloud recommends replacing raw AI Studio API keys with individual logins and per-app service accounts.
- Narrow IAM roles, separate dev and prod projects, and Secret Manager limit what a leaked credential can do.
- A spend cap budget, in Preview, can pause a service once estimated spend passes a set amount.
Why raw API keys become a problem
A Gemini prototype usually starts with a key from Google AI Studio pasted into a coding agent or an app config. That is fast, and it is fine while one developer is working alone. The problem starts when the prototype gets real users and the key is copied into .env files, shell profiles, chat threads and sometimes the app itself.
Google Cloud's guide describes an AI Studio key as a bearer token: whoever holds it can use it, it does not expire on its own, and it is not tied to a person or workload. It also has no spending limit unless one is added. The guide's example is an account that normally spends $180 a month, where a leaked key used by automated scrapers pushes the bill into the tens of thousands before the first billing alert arrives. Under the shared responsibility model, the customer pays for usage made with its own valid credentials.
The guide's advice is to start with a scan of the repo for strings shaped like Google API keys and for literal api_key= values. The scanner reports file and line but not the key itself, and it exits with an error so it can run in CI.
Individual logins instead of shared keys
The first step is to give each developer one login. Running gcloud auth application-default login opens a browser sign-in and stores a short-lived credential on the machine. Google Cloud SDKs find that credential automatically, so there is no key to copy or paste.
The same login works across models in Model Garden. According to the guide, switching models within an SDK means changing one string. For Gemini, the Google Gen AI SDK call moves to Gemini Platform with enterprise=True, and the guide notes that older samples use vertexai=True, which current SDK versions still accept. Claude can be called through Anthropic's SDK with the same login, and open models such as OpenAI's gpt-oss can be reached through the OpenAI SDK pointed at Google Cloud. Partner models need a one-time Enable on their Model Garden card in each project. Every call then lands on one Google Cloud bill, which the guide presents as a way to compare models on cost and quality.
Service accounts and least-privilege roles
The application itself should not carry a key either. The guide says the code stays the same: on a laptop, Application Default Credentials picks up the developer's login, while on Cloud Run, GKE or Compute Engine it uses a short-lived token for the attached service account, refreshed automatically. A token that leaks typically lasts about an hour and carries only that service account's permissions.
Google Cloud recommends keeping development and production in separate projects, so a mistake in one does not spend the other's budget. For access, it recommends the roles/aiplatform.user role rather than Editor or Owner. Google suggests granting it to a Google group for people, so that offboarding is a group membership change, and to the service account for the app. The guide also mentions organization policies such as vertexai.allowedModels to limit which models can be called, an audit for service accounts holding Owner or Editor, and org policies that block creation of new API keys and service account keys.
Secret Manager and spend caps
Keys for third-party services such as Stripe, Slack or an email provider cannot be avoided entirely. The guide says they belong in Secret Manager, with read access granted per secret to the identity that needs it. Test keys can go to the developer group, while live keys stay in the production project and are readable only by the app's service account. Rotation means adding a new secret version, and the guide notes that old AI Studio keys remain live until they are deleted.
For cost control, the guide describes a spend cap budget, currently in Preview. When estimated spend for one service in one project passes the set amount, new requests to that service are paused until the cap is lifted or the next month starts. Alerts go to billing admins and project owners at 50%, 80% and 100%. The guide lists the limits: each cap covers one project and one service, enforcement runs on estimated cost and is not instant, overage is still billed, and after a cap is lifted the service can take up to an hour to recover. It suggests separate caps for dev and prod, plus lower Agent Platform quotas as a second layer.
The guide also covers Model Armor, which screens prompts and responses for prompt injection, jailbreak attempts, malicious URLs and sensitive data. Only the outline of that section appears in the source text provided.
Why it matters
For teams, the practical change is that an AI prototype stops being a single shared secret and becomes a set of identities with defined permissions. Onboarding and offboarding move to group membership, the app's credentials are short-lived and scoped, and spending can be capped per project and per service. Teams that have already shipped a key into a repo, chat or client bundle should, according to the guide, rotate or delete it this week. Teams planning a launch should read the guide's broader production checklist before onboarding paying customers.
Sources
This article was written by Blozhik from the reporting below. Read the originals for full detail.
GoUltimate guide for fixing your team’s API keysGoogle Cloud Blog