# Ultimate guide for fixing your team’s API keys

> Source: <https://cloud.google.com/blog/topics/developers-practitioners/how-to-fix-your-teams-api-keys/>
> Published: 2026-11-20 17:00:00+00:00

**Recommendation:** Move team members to Application Default Credentials and run apps under least-privilege service accounts, then add the key scanner to CI and put remaining keys in Secret Manager with spend caps and monitoring.
More in the playbook "Securing agents and AI tools": <https://wpnews.pro/playbooks/agent-security>

Most Gemini prototypes start the same way. You grab an API key from [Google AI Studio](https://aistudio.google.com/), then paste it into your coding agent to start building a prototype. That speed is the point, and shouldn’t be slowed down. 

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. The app has one more, baked into its config.

For example, imagine an account that normally spends $180 a month. One of those keys ends up in a public repo, a Slack channel or a mobile app bundle. Automated scrapers find it within minutes and use it to run large workloads. By the time the first billing alert arrives, the bill is in the tens of thousands. Under the [shared responsibility model](https://cloud.google.com/architecture/framework/security/shared-responsibility-shared-fate), the customer pays for usage made with their own valid credentials. For a seed-stage company, that’s runway gone in a weekend.

In our recent post, [10 questions every startup should answer before moving to production with their AI prototype](https://cloud.google.com/blog/topics/developers-practitioners/10-questions-for-your-startup-developers), we covered the whole path from prototype to production. This post goes deeper on one part of it: getting off raw API keys entirely.

Here is what this guide covers:

**Authorize your people.** Give everyone on the team one login with Application Default Credentials and use it to call Gemini, Claude and open models. Steps 1 and 2 take about five minutes.

**Authorize your application.** Run your app under its own service account with only the access it needs. Steps 3 and 4.

**Lock down what's left.** Move the remaining keys into Secret Manager, then add spend caps, guardrails and monitoring. Step 5 and the closing sections.

The code for every step is in a [companion repo](https://github.com/sergiov8/secure-your-keys-demo) with runnable samples and offline tests.

An AI Studio key is a bearer token. Whoever holds it can use it. It doesn't expire on its own. It isn't tied to a machine, a person or a workload. It has no spending limit unless you add one. When someone leaves the company, nobody knows which keys to revoke.

That is fine on your laptop while you are the only user. It stops being fine when any of these is true:

A key has left your laptop. It was shared in chat, committed to a repo or deployed to a server.

More than one person on the team needs to call the API.

You are spending more than a few hundred dollars a month, or you are about to onboard paying customers.

If one of those describes you, do the switch this week.

Before changing anything, find out where your keys are. The repo includes a small scanner that looks for strings shaped like Google API keys and for api_key= set to a literal value. It reports the file and line but never the key itself. It also exits with an error, so you can drop it into CI:

Each person on the team runs one command:

A browser window opens, you sign in with your work account and gcloud stores a short-lived credential on your machine. Every Google Cloud SDK finds it automatically. There is no key to copy, paste or leak.

Then point your tools at the team project:

Someone has to grant you access to the project first. Step four shows how.

That single credential works for every model in [Model Garden](https://cloud.google.com/model-garden), not only Gemini. You don't need new accounts, new keys or separate invoices. Within each SDK, switching models means changing one string.

**Gemini**, with the [Google Gen AI SDK](https://github.com/googleapis/python-genai). If your prototype builds the client with api_key=..., this is the only change:

enterprise=True sends the call to Gemini Platform instead of AI Studio. Older samples call the same flag vertexai=True, and current SDK versions accept both.

**Claude**, with [Anthropic's SDK](https://docs.cloud.google.com/gemini-enterprise-agent-platform/models/partner-models/claude/use-claude) and the same login:

**Open models** such as OpenAI's [gpt-oss](https://docs.cloud.google.com/gemini-enterprise-agent-platform/models/maas/openai/gpt-oss-120b), with the OpenAI SDK pointed at Google Cloud:

Two things to know:

Partner models like Claude need a one-time **Enable** on their Model Garden card in each project. After that, everyone with access can call them.

OpenAI's GPT-6 models [arrived in Model Garden](https://cloud.google.com/blog/products/ai-machine-learning/google-cloud-brings-openai-models-to-customers) on October 21 in private preview for select enterprise customers. When they open up, the same login will work for them too.

Every call lands on one Google Cloud bill, which makes it easier to compare models on cost and quality.

Your app needs the same thing your developers just got: an identity instead of a key. For a workload, that identity is a service account.

The good news is that the code from Step 2 doesn't change. On your laptop, ADC picks up your own login. On Cloud Run, GKE or Compute Engine, it picks up a short-lived token for the service account attached to the workload, refreshed automatically. So there is nothing in your codebase to leak. A token that escapes is short-lived, usually about an hour, and it only carries the permissions of one service account.

Create the service account and deploy with it:

Keep people and production apart. Developers work in my-startup-dev under their own logins, and the app runs in my-startup-prod under its service account. A mistake in one doesn't spend the other's budget.

Removing keys solves the leak problem. The next question is what each identity is allowed to do. If a person or a service account holds the Editor or Owner role, a stolen login or token can still delete resources, change permissions or read data it never needed.

Calling models takes one role, [roles/aiplatform.user](https://cloud.google.com/vertex-ai/docs/general/access-control). The grant looks the same for both kinds of identity.

For people, grant it to a Google group, not to individuals. Onboarding and offboarding then become a group membership change:

For the app, grant it to the service account:

It takes about 30 seconds longer than granting Editor. If anything is compromised later, the attacker gets one narrow role instead of the whole project. When someone leaves, remove them from the group and their access ends everywhere at once.

In the Cloud Console, the Grant access dialog has a **Help me choose roles** button. You describe the task in plain English and [Gemini suggests predefined roles](https://cloud.google.com/iam/docs/role-picker-gemini). By default the suggestions cover common tasks, which usually means a service's broad Admin, Editor or Viewer role. To get the narrow roles, say so:

What is the narrowest access a service account needs to call Gemini models on Agent Platform?

Three more controls are worth knowing:

If your project sits in an organization, the [vertexai.allowedModels](https://docs.cloud.google.com/gemini-enterprise-agent-platform/models/control-model-access) policy limits which models anyone can call. You list values such as publishers/google/models/gemini-4-hydrogen:predict, and everything else is blocked.

The repo includes a one-line audit that lists every service account holding Owner or Editor on a project. Run it now and again before each launch.

To stop new keys from being created, enforce [Org Policies](https://docs.cloud.google.com/organization-policy/overview) denying CREATE on [apikeys.googleapis.com/Key](https://docs.cloud.google.com/api-keys/docs/custom-constraints) for API keys and [iam.managed.disableServiceAccountKeyCreation](https://docs.cloud.google.com/organization-policy/restrict-service-accounts#disable_service_account_key_creation) for service account keys.

Some keys won't go away, like Stripe, Slack or your email provider. They belong in [Secret Manager](https://cloud.google.com/secret-manager), not in .env files, chat threads or the repo. Access works the way it did in Step 4: grant read access on each secret to the identity that needs it.

Test keys go to the developer group:

Anyone in the group can then fetch the key with their own login:

Live keys stay in the production project, readable only by the app's service account. The app reads them at startup:

Reading --data-file=- from standard input keeps the value out of your shell history. Every read is tied to a named person or service account, and rotating a key means adding one new version. Nothing is redeployed and no file is copied between laptops.

Then finish the job. Go to the [AI Studio API keys page](https://aistudio.google.com/apikey) and delete every key, personal or shared, that ever left a laptop. A key you have moved away from is still live until you delete it.

Once your people and your app run on identities in a Google Cloud project, several protections become available that a bare key can't offer. You don't need all of them on day one. They are worth knowing about before your first launch.

Standard budget alerts send email while the bill keeps climbing. A [spend cap budget](https://cloud.google.com/billing/docs/how-to/budgets-spend-caps), currently in Preview, does more. When estimated spend for one service in one project passes the amount you set, new requests to that service are paused until you lift the cap or the next month starts. Alerts go to billing admins and project owners at 50%, 80% and 100%.

You can create one in the console under **Budgets & alerts** by choosing **Spend cap enforcement**, or through the Budget API. The repo wraps the API call and has a dry-run flag so you can inspect the request first:

Know the limits before relying on it. Each cap covers a single project and a single service. Agent Platform, the Gemini API, Cloud Run and Cloud Run functions are eligible today. Enforcement runs on estimated cost and is not instant. Any overage is billed as normal, so set the number below the amount you can actually afford to lose. A cap also pauses usage covered by commitments, and after you lift it the service can take up to an hour to recover.

Set one cap on the dev project and another on prod. An experiment then can't drain the budget your customers depend on. For a second layer, lower your [Agent Platform quotas](https://cloud.google.com/docs/quotas/view-manage) to what you really need, so a bug or an agent stuck in a loop runs into a ceiling instead of your card limit.

As soon as real users can type into your app, someone will try to make it ignore its instructions. [Model Armor](https://cloud.google.com/security-command-center/docs/model-armor-overview) screens prompts and responses for prompt injection, jailbreak attempts, malicious URLs and sensitive data. You create a template once, check each prompt against it and only call the model when it comes back clean. The repo has both halves.

If your product lets the model write and run code, for example to analyze a customer's spreadsheet, that code should not run inside your application process. With [code execution](https://cloud.google.com/vertex-ai/generative-ai/docs/code-execution), the model runs Python in a Google-managed sandbox and hands back the result:

The generated code never sees your environment variables, your files or your database.

[Security Command Center](https://cloud.google.com/security-command-center) surfaces threats and misconfigurations across the project, such as a service account suddenly calling an API it has never used or a workload contacting an unfamiliar host. Together with Cloud Audit Logs, which record who changed what and when, it also gives you the answers your first enterprise customer's security review will ask for. Because every call now comes from a named person or service account, those logs mean something.

For your team:

Everyone runs gcloud auth application-default login.

Grant roles/aiplatform.user to one Google group, and enable the partner models you want.

Move shared test keys into Secret Manager, readable by the group.

For your app:

Deploy with a service account that holds roles/aiplatform.user and nothing broader.

Move live third-party keys into Secret Manager, readable only by that service account.

Set a spend cap on each project below the amount you can afford to lose.

For both: Run the key scanner, then delete every AI Studio key at [aistudio.google.com/apikey](https://aistudio.google.com/apikey).

None of this slows down building. You keep the speed of the prototype and every model in Model Garden stays one string away. Nobody on the team has to guard a key again. The full code, with a sample for every step and bonus above, is in the [companion repo](https://github.com/sergiov8/secure-your-keys-demo).

Have a scenario you'd like us to cover next? Reach us at [Google Cloud for Startups](https://cloud.google.com/startup).
