ReadingResearchRadarInvestment framework
Sign in / Sign up
← Back to reading
NewsMaterial4 min readDisconfirmAI Editorial

How to replace AI API keys with one login per person and a spend cap that pauses the service

Sergio Villani, a technical solutions engineer at Google Cloud, describes a five-step method for teams to stop using raw AI API keys: give each person one login via Application Default Credentials, run the app under a service account with only the model-calling role, move remaining third-party keys into Secret Manager, and add spend caps that pause new requests when estimated cost exceeds a threshold. The guide includes commands, code samples and a companion repo.

2026-11-21

Raw API keys are how most Gemini prototypes begin. You grab a key from Google AI Studio, paste it into your coding agent, and start building. That speed is the point. The trouble starts later, when the prototype gets real users and the key comes along unchanged. By then it usually isn't one key — every developer has their own, often several, sitting in .env files, shell profiles and chat threads, and the app has one more baked into its config.

Sergio Villani, a technical solutions engineer at Google Cloud, describes a five-step method for teams to get off raw API keys entirely. The guide is specific to Google Cloud's tooling and assumes a Google Cloud environment.

The starting point is a concrete failure mode. An AI Studio key is a bearer token: whoever holds it can use it, it does not expire on its own, it is not tied to a machine, person or workload, and it carries no spending limit unless you add one. Villani illustrates the risk with a hypothetical: imagine an account that normally spends $180 a month. One key leaks into a public repository, a Slack message or a mobile app bundle. Automated scrapers find it within minutes and run large workloads. Under the shared responsibility model, the customer pays for usage made with their own valid credentials. By the time the first billing alert arrives, the bill is in the tens of thousands. For a seed-stage company, that is runway gone in a weekend.

The method has five steps. First, each person on the team runs gcloud auth application-default login. A browser window opens, they sign in with their work account, and the tool stores a short-lived credential on their machine. There is no key to copy, paste or leak. Every Google Cloud SDK picks up this credential automatically. Second, that single credential works for every model in Model Garden, not only Gemini. Switching between Gemini, Claude and open models means changing one string in the SDK call, not obtaining new keys or separate invoices.

Sign in / Sign up
ReadingResearchRadarInvestment framework

Third, the application itself needs its own identity. On Cloud Run, GKE or Compute Engine, Application Default Credentials picks up a short-lived token for the service account attached to the workload, refreshed automatically. The guide recommends keeping people and production apart: developers work under their own logins in a dev project, the app runs under its service account in a prod project, and a mistake in one does not spend the other's budget.

Fourth, each identity gets only the access it needs. Calling models requires one role, roles/aiplatform.user. For people, the guide recommends granting it to a Google group rather than to individuals, so onboarding and offboarding become a group membership change. When someone leaves, removing them from the group ends their access everywhere at once. For the app, the same role goes to the service account. The guide notes that this takes about thirty seconds longer than granting Editor, and that if anything is compromised later, the attacker gets one narrow role instead of the whole project.

Fifth, keys that cannot go away (Stripe, Slack, email providers) move into Secret Manager, with read access granted to the specific identity that needs them. Test keys go to the developer group; live keys stay in the production project, readable only by the app's service account. The guide also recommends running a key scanner that looks for strings shaped like Google API keys and for api_key= set to a literal value, reporting file and line but never the key itself, and exiting with an error so it can run in CI.

Once identities replace keys, several protections become available that a bare bearer token cannot offer. A spend cap budget, currently in Preview, pauses new requests to a service when estimated spend for one service in one project passes the amount you set. Alerts go to billing admins and project owners at 50%, 80% and 100%. The guide recommends setting one cap on the dev project and another on prod, so an experiment cannot drain the budget customers depend on. It also suggests lowering Agent Platform quotas as a second layer, so a bug or an agent stuck in a loop runs into a ceiling instead of a card limit.

Model Armor screens prompts and responses for prompt injection, jailbreak attempts, malicious URLs and sensitive data. Security Command Center surfaces threats and misconfigurations, such as a service account suddenly calling an API it has never used or a workload contacting an unfamiliar host. Because every call now comes from a named person or service account, Cloud Audit Logs mean something: they record who changed what and when, which the guide notes is what an enterprise customer's security review will ask for.

The method has limits worth naming. The spend cap feature is in Preview. Enforcement runs on estimated cost, not actual usage, and is not instant; any overage is billed as normal, so the guide advises setting the number below the amount you can actually afford to lose. Each cap covers a single project and a single service. After you lift a cap, the service can take up to an hour to recover. The companion repo contains runnable samples and offline tests for each step.

Sources

  • cloud.google.comGoogle Cloud Blog↗
Continue researching →