← All stories · Leaked secrets & API keys

Restrict and cap a Gemini API key

Stolen Gemini API key: $82K in charges in 48 hours · Security incident · Hacker News · andrasbacsai · Feb 2026

A developer reported a stolen Google Cloud API key that generated about $82,000 of Gemini charges in two days, against a normal monthly spend of about $180.

Lesson

Restrict Google API keys by API and referrer, and set billing budgets with alerts. See our API key guide.

Fix prompt

Copy this into your own AI tool (Cursor, Lovable, Claude Code, Bolt…). It's general guidance written by us. Review what the AI suggests before applying it.

I'm a beginner and want to make sure my API keys are safe in my Gemini project. 1) Search the code for hardcoded keys or tokens and for secrets in variables that ship to the browser (NEXT_PUBLIC_, VITE_, REACT_APP_). List the file and line, but don't print the values. 2) For each one, tell me whether it's meant to be public (like a Supabase anon key) or secret. 3) For secret ones, show me how to move them to server-side env vars and call the provider through a server route. 4) Give me the steps to rotate each exposed key in the provider's dashboard and set a spending limit. 5) Make sure .env is in .gitignore and in my AI tool's ignore file. Don't change anything until I've approved your plan. Never ask me to paste API keys, passwords or .env contents; tell me where to check them myself.
GeminiGoogle Cloud

Source: Hacker News ↗

The Honest Build. Real stories, not hype.

Every week: real stories of what building with AI actually took, the one lesson worth keeping, and the security slip-ups to avoid. Free, unsubscribe anytime.