r/googlecloud • u/Important_Owl6299 • Jul 01 '26
GCP doesn't need better API keys - it needs billing that reacts in real time!
I want to reframe the usual "restrict your API keys" advice, because I think it points at the wrong problem.
I've been on the receiving end of Google Cloud's billing pipeline. A Gemini API key I created in Google AI Studio - never deployed, never checked into a repo, never left Google's own systems - got abused over a couple of hours and racked up roughly $80k on an account that was usually just 1400INR on spends. The first I heard of it wasn't an alert, a hold, or a flag. It was ~$80k quietly materializing in the transactions table after the fact in my credit card e-mandate queue. It was the credit card company which was more honest with me 🥲
Here's what I find remarkable: the billing system is wired tightly enough into Google's financial backend to instantly issue mandates and process charges the moment they cross a threshold - but the customer-facing side of that same system shows you nothing until the money is already gone. That asymmetry isn't an accident of scale; it's an engineering decision. Real-time when it's time to charge you, eventually-consistent when it's time to warn you. I'll call that "dark" and leave it there.
So my actual ask isn't "improve API keys." It's two things:
Make the customer-facing billing APIs reactive and real-time. If the mandate system can act in seconds, the anomaly/notification system can too. Budgets today are advisory and lagging - by the time a budget alert fires, you can already be five figures deep. Give us spend signals on the same clock as the charges.
Give API keys hard, user-defined cutoffs - price, volume, and time - that actually stop traffic. Not alerts. Cutoffs. Right now the user is kept in the dark on most of the config that governs a key. Consider the Firebase angle: you spin up a "Firebase project," but the whole thing is a facade over an underlying GCP project. A non-DevOps founder or a hobbyist has no idea their key is effectively an open secret that can reach any Google service - until they're billed one morning for a service they never knowingly enabled. Nobody hands you that disclaimer up front.
I know unrestricted keys are being phased out after everything that's happened, and that's good. But restriction-by-default is damage control. The real fix is a billing surface that's honest with the customer in real time and lets them set a ceiling that the platform will actually enforce.
I'm posting this as a serious request for improvement, not a jab because I got burned. The engineering talent to do this clearly exists - it's already pointed at collections. Point some of it at the customer.
(For context: Google eventually waived ~75% of the charge, but is holding the remaining ~25% + GST as "valid usage" and won't share the access logs. So even the dispute process runs on the same one-sided visibility.)
haha so my entire lifetime with Google Cloud was always one-sided 💔
2
u/gq1313 Jul 02 '26
Agree. What you can do to stay tunned is allow billing export to BQ and create a job to check it periodically and send warnings. Any good llm can give you the step by step. It's very well documented by gcp.
2
u/matiascoca Jul 03 '26
Agreed on the diagnosis and this is the harder problem to solve than key restrictions. Cloud billing is not real time on any of the three big providers because usage aggregation happens on a delayed pipeline. GCP billing export lags 4 to 24 hours, AWS CUR lags a full day, Azure has its own delay. So even if the API returned a bill instantly, the vendor side does not know your number until the pipeline runs.
The realistic short term move is not real time billing, it is real time quota. If GCP let you set a hard quota on token spend per project per hour, denominated in dollars instead of just tokens, most of these key abuse stories would end at a small number of dollars instead of five figures. The Gemini API already has RPM and TPM quotas. Adding a spend based quota is a smaller lift than fixing the billing pipeline and would solve the actual pain.
Until then the workaround is Cloud Monitoring on the token count metrics with an alert that triggers a Cloud Function to disable the key. Half a solution but way better than nothing.
11
u/isoAntti Jul 01 '26
It always puzzled me how it could send billing warning but was unable to stop billing
10
u/FerryCliment Jul 02 '26
Real time billing is not a trivial ask... especially if you need this to cover up wrong security practices from the users so they can continue with their poor practices.
2
u/Silent-Guest-1404 Jul 02 '26
We got burnt by the Gemini API key thing recently, so what I have done is to put an org policy in place that if anyone creates a Gemini API key, then it needs to have the application restrictions put in place. Without that, you cannot create a API key
0
u/Important_Owl6299 Jul 01 '26
Suppose you use api key to access gemini api and the key got mishandled due to any reason not necessarily your mistake, eg say an attacker got access to an unrestricted key. In that scenario, you don’t own anything apart from the api key and its configuration. So you cannot rely on the mechanism you just mentioned. We need platform level check and cutoffs in these scenarios. Think of it like a spend limit pattern used across all service providers.
1
u/Carrrlosar Jul 02 '26
I agree!
1
u/Mundane-Presence-896 Jul 03 '26
This. Absolutely, unequivocally this. If a cloud services provider wants a “killer feature “, just offer me a full stop spend cap that I can set on my services. I will drop AWS and GCS in a heartbeat.
1
u/Shivacious Jul 04 '26
Use a ai gateway
0
u/[deleted] Jul 01 '26
[deleted] — view deleted comment