€54k spike in 13h from unrestricted Firebase browser key accessing Gemini APIs
TL;DR Highlight
Enabling Firebase AI Logic exposed an unrestricted browser key, and €54k in Gemini charges hit within 13 hours.
Who Should Read
Developers with Firebase/GCP projects who added Gemini and have API keys sitting in client-side code
Core Mechanics
- Enabling Firebase AI Logic triggered the spike
- The project was over a year old and only used Firebase Authentication.
- Within hours of enabling Firebase AI Logic, Gemini API charges reached €54,000+.
- Traffic didn't match real users
- The author said it looked automated.
- Usage stopped once they disabled the API and rotated credentials.
- Alerts arrived hours late
- The €80 budget alert and the anomaly alert both fired hours late.
- Costs were around €28,000 by the time they reacted and settled at €54,000+ due to delayed cost reporting.
- The billing adjustment was denied
- They gave Google Cloud support logs and analysis.
- The charges were classed as valid usage since they came from their project.
- Google outlined new safeguards
- Logan Kilpatrick pointed to spend caps (tier 1 is $250/month) and project spend caps.
- Reporting has a 10-minute delay, unrestricted keys are being phased out, and new users get Auth keys by default.
- Keys in client code are risky
- He said not to put keys in client-side code, since exposed keys can incur costs even with restrictions.
- Keys from AI Studio are Gemini-only by default, but keys from other Cloud areas can work across services.
Community Reactions
- Many others reported similar hits
- The thread had reports of $13,000, $67k+ in 19 hours, $6,486, and 3.5K USD.
- A HN commenter said they caught $26k early and the refund request was under review.
- Complaints about no hard cap, plus a counterview
- A commenter said a $100 budget alert only emailed 5 hours after it was exceeded.
- Another argued real-time cost calculation is hard and that refunds happen often enough.
- Budget alert plus Pub/Sub cutoff suggested
- Commenters described wiring budget alerts to Pub/Sub and a Cloud Function that disables project billing.
- A commenter who said they work at Google pointed to the documented billing disconnect but warned against using it in production.
- Two key restrictions should be default
- One commenter said to restrict by HTTP referrer and by API (generativelanguage.googleapis.com only).
- Others criticized that Google long said API keys weren't secrets, and that Gemini broke this.
How to Apply
- Scan your Firebase keys for Gemini exposure
- Today, log into gcloud and firebase CLI and run the scan script shared in the comments, or the snippet below on public/.
- A 200 from the models or files endpoint on generativelanguage.googleapis.com means the key is exposed.
- Add API and referrer restrictions to keys
- In Cloud Console under APIs & Services → Credentials, restrict APIs so Gemini is excluded.
- On the same page, add HTTP referrer restrictions limited to your domains.
- Set a project spend cap on Gemini
- Use project spend caps from the Gemini API billing docs on dev projects.
- Set it low, since reporting has a 10-minute delay.
- Wire a budget alert to an automatic cutoff
- Send budget alerts to Pub/Sub and have a Cloud Function disable billing.
- Use only on internal or test projects, not production.
Try It
# Paste in terminal: find AIzaSy keys in public/ bundles and check whether Gemini accepts them (simplified version of the comment script)
npm i -g firebase-tools
grep -rhoE 'AIzaSy[A-Za-z0-9_-]{33}' public/ | sort -u | while read k; do
code=$(curl -s -o /dev/null -w '%{http_code}' "https://generativelanguage.googleapis.com/v1beta/models?key=$k")
echo "$k -> HTTP $code (200 means exposed)"
doneTerminology
Related Papers
A Beginner's Guide to Local AI with Inkling, Qwen, and Unsloth
Install Unsloth Desktop, load a quantized Qwen model, and share a private ChatGPT-like AI on your home LAN.
Muru – AI-assisted Rust server for Python apps by mod_WSGI's creator
mod_wsgi's creator is building Muru, an AI-assisted Rust ASGI/WSGI server, documenting it in public
87% of the Anthropic power will come from gas and 11% from coal in 2028
Analysis of Anthropic's contracted data centers: 87% gas, 11% coal power in 2028
Anthropic’s Nasdaq debut
Anthropic listed on Nasdaq and closed its first day below its opening price.
OpenAI still has a WebRTC Problem
WebRTC drops late audio, hurting voice AI; MoQ retransmits and buffers instead
Gemini 4 Neon
Gemini 4 Neon cuts cost per task 32% versus Carbon, at $3 input and $15 output per million tokens
AI is killing All About Berlin
After Google AI Overviews, a Berlin guide site lost 70-75% of its traffic.
Not Everything Needs an LLM
PostHog used small decision models to skip 98.7% of expensive LLM calls
Related Resources
- https://discuss.ai.google.dev/t/unexpected-54k-billing-spike-in-13-hours-firebase-browser-key-without-api-restrictions-used-for-gemini-requests/140262
- https://ai.google.dev/gemini-api/docs/billing#tier-spend-caps
- https://ai.google.dev/gemini-api/docs/billing#project-spend-caps
- https://trufflesecurity.com
- https://news.ycombinator.com/item?id=47156925