Why does a leaked API key get used within minutes?
API keys: bots scan every public push for keys and try them within minutes; replace a leaked key at once · Beginner · 5 min · safety, llm · after Rate limits (RPM, TPM, RPD), Free tiers: a busy GPU makes tokens for cents, and free buys customers, data or idle hours
An API key is your account’s password. Bots scan every public GitHub push, and in honeypot tests leaked keys were used within 2 to 5 minutes. Keep keys in environment variables, and replace a leaked key at once.
1 Guess first
An API key is a password that comes with your account. Whoever sends it is you: the calls use your free limit, or your money. Keys have a recognisable shape, so a program can scan any public text for them: commits, pastes, posts.
3 Look
A leaked key, minute by minute
1 / 5An API key is a password that comes with your account. Whoever sends it is you: the calls count against your free limit, or your bill.
# .env (listed in .gitignore) GEMINI_API_KEY=<your key>
Keys have a recognisable shape, so a program can find one in any text it reads: a commit, a paste, a screenshot’s caption.
Google and GitHub docs, read 2026-10-26; no real key shown
An API key is your account’s password. Keep it in an environment variable on your machine or server, never in the code you share.
Get a key the safe way: free AI APIs with no credit card · sites that sell “shared” keys: scam list
A public key is a used key: the scan takes seconds, and the bill is yours until you replace it.
4 You are the model
Scanner bots read anything public. For five places a key can sit, say whether it stays private or is exposed.
key 1 of 5 · can a scanner bot find it?
In a .env file that .gitignore keeps out of the repo, read as an environment variable.
Rules from Google’s and GitHub’s docs, read 2026-10-26
You are the scanner bot’s target. Say where each key is safe.5 Check
If a key leaks, replace it first, then clean up. Google’s checklist: create a new key, deploy it, disable the old one, then check your usage. GitHub warns that deleting the commit does not remove the key from clones, forks or old commit links.
7 Say it back
8 Mission · 5 min
Pick a free API with no card, create a key, and store it in a .env file listed in .gitignore. Then rehearse the leak drill once: create a second key, switch to it, and disable the first.
Three quick ones
Drawn at random from this lesson's pool; different next time.
Done?
Get an email when new lessons come out
New lessons arrive in the weekly digest, only in a week that has one. You confirm by email first; unsubscribe in one click.
Go deeper
Sources
- Orca Security, “2023 Honeypotting in the Cloud Report” (2023-06-20, https://orca.security/resources/blog/2023-honeypotting-in-the-cloud-report/, checked 2026-10-26): research January to May 2023, honeypots on 9 kinds of cloud resources each holding an AWS key; “We saw key usage on GitHub within 2 minutes”; secrets on GitHub, HTTP and SSH found in under five minutes
- Palo Alto Networks Unit 42, “EleKtra-Leak: Cloud-Based Cryptojacking Campaign Targeting AWS IAM Keys on GitHub” (2023-10-30, updated 2023-11-06, https://unit42.paloaltonetworks.com/malicious-operations-of-exposed-iam-keys-cryptojacking/, checked 2026-10-26): the actor detected and used exposed IAM credentials “within five minutes of their initial exposure on GitHub”; 474 miners seen from 2023-08-30 to 2023-10-06
- GitHub blog, “GitHub found 39M secret leaks in 2024. Here’s what we’re doing to help” (2025-04-01, https://github.blog/security/application-security/next-evolution-github-advanced-security/, checked 2026-10-26): “more than 39 million secrets were leaked across GitHub in 2024 alone”; “Every minute GitHub blocks several secrets with push protection”
- GitGuardian, “The State of Secrets Sprawl 2026” (2026-03-17, https://blog.gitguardian.com/the-state-of-secrets-sprawl-2026/, checked 2026-10-26): 28.65 million new hardcoded secrets in public GitHub commits in 2025, a 34% increase year over year; AI service secrets reached 1,275,105, up 81%; of valid secrets found in 2022, the January 2026 retest found the validity rate “still above 64%”
- Sysdig, “LLMjacking: Stolen Cloud Credentials Used in New AI Attack” (2024-05-06, https://sysdig.com/blog/llmjacking-stolen-cloud-credentials-used-in-new-ai-attack/, checked 2026-10-26): attackers resell LLM access bought with stolen cloud credentials; worst case Claude 2.x at quota, “(500K tokens/1000 * $0.016) * 60 minutes * 24 hours * 4 regions = $46,080 / day”, “the cost to the victim can be over $46,000 per day”
- Google, “Using Gemini API keys” (https://ai.google.dev/gemini-api/docs/api-key, last updated 2026-10-06, checked 2026-10-26): “Never check API keys into source control systems like Git”; “Do not hardcode API keys directly in web or mobile apps”, use a backend; “Read keys from environment variables”, `GEMINI_API_KEY`; leak response checklist: create a replacement key, deploy, disable the old key once the new one is verified (“Do not delete the old key until the new key is fully active”), review billing and API usage
- GitHub Docs, “Removing sensitive data from a repository” (https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/removing-sensitive-data-from-a-repository, checked 2026-10-26): “as a first step you need to revoke and/or rotate that secret”; after rewriting history, commits may still be accessible “In any clones or forks of your repository”, “Directly via their SHA-1 hashes in cached views on GitHub” and “Through any pull requests that reference them”
- GitHub Docs, “About secret scanning for partners” (https://docs.github.com/en/code-security/secret-scanning/introduction/about-secret-scanning-for-partners, checked 2026-10-26): GitHub scans public repositories and public npm packages and “alerts the relevant service provider whenever a secret is detected in a commit”; the provider decides whether to revoke it, issue a new one or contact you. “Supported secret scanning patterns” (https://docs.github.com/en/code-security/secret-scanning/introduction/supported-secret-scanning-patterns, checked 2026-10-26): OpenAI, Anthropic, Google, Groq and Hugging Face keys are partner patterns
- The five places in the scanner-bot step are illustrative; each answer follows the Google and GitHub rules above
Published Oct 26, 2026 · updated Oct 26, 2026