Most Gemini prototypes start the same way. You grab an API key from Google AI Studio, 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, 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, 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 with runnable samples and offline tests.
Why a raw key is different
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: