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.
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.