Prompt
Why do my API keys keep getting abused and how do I stop it?
Latest observation
Oct 22, 2026
OpenAI APIWeb search: off
API keys get abused mostly because they’re often treated like “just a secret,” but in practice they’re bearer tokens: anyone who has one can usually use it. Abuse happens when a key is exposed, over-permissive, or not monitored.
Common reasons keys get abused
-
Leaked in code or logs
- Committed to GitHub
- Printed in app logs, error messages, CI output
- Hardcoded into mobile apps or frontend code
-
Stored insecurely
- In plain text
.envfiles shared too widely - In browser-local storage or client-side config
- In unsecured secrets managers or backups
- In plain text
-
Too much permission
- One key can do everything
- No scope restrictions or environment separation
-
No usage controls
- No rate limits
- No IP allowlists
- No domain/referrer restrictions
- No quota caps
-
Key reuse
- Same key used across dev/staging/prod or multiple services
- Shared among teammates or vendors
-
Credential stuffing / guessing
- Weak or short keys
- Predictable naming or generation patterns
-
Third-party compromise
- A contractor, plugin, or CI system got breached
How to stop it
1) Rotate the keys now
- Revoke the compromised key immediately.
- Issue a new one.
- If you can’t tell which key is exposed, rotate all high-risk keys.
- Treat rotation as urgent if you see unusual usage.
2) Make keys harder to misuse
- Use separate keys per environment: dev, staging, prod
- Use separate keys per service/integration
- Give each key the minimum permissions needed
- Set expiration dates if supported
3) Add access restrictions
Depending on your API/provider, enable:
- IP allowlists
- HTTP referrer restrictions for browser-based use
- OAuth/service accounts instead of raw API keys where possible
- Per-key quotas and rate limits
4) Move secrets out of unsafe places
- Keep keys in a proper secrets manager:
- AWS Secrets Manager / SSM Parameter Store
- GCP Secret Manager
- Azure Key Vault
- Vault, Doppler, 1Password, etc.
- Never ship secret keys to the browser or mobile client unless the API is designed for that and the key is tightly restricted.
5) Monitor and alert
Track:
- Request volume per key
- New geographies / IPs
- Spikes in error rates
- Unusual endpoints or usage times
- Quota exhaustion
Set alerts for:
- Sudden traffic jumps
- Access from unexpected IP ranges
- Repeated auth failures
- Cost anomalies
6) Find the leak source
Check:
- Git history and public repos
- CI/CD logs and build artifacts
- App logs and exception traces
- Docker images and container env vars
- Browser bundles
- Shared documents, tickets, chat history
- Old backups
Use secret scanning tools:
- GitHub secret scanning
- TruffleHog
- Gitleaks
- GitGuardian
7) Reduce blast radius
- Use a proxy/backend to call the external API instead of exposing keys to clients
- Put server-side authorization in front of expensive actions
- Add per-user limits and abuse detection on your side
- Isolate production keys from non-production systems
A good practical setup
If you’re starting from scratch, aim for:
- One key per environment
- One key per service
- Minimal permissions
- IP restrictions where possible
- Rate limits and quotas
- Central secret storage
- Logging and anomaly alerts
- Regular rotation
If abuse is happening right now
Do this immediately:
- Revoke the affected key(s)
- Generate replacements
- Check logs for when abuse started
- Identify exposed source
- Remove the leak
- Add monitoring and restrictions
- Audit other keys for similar exposure
If you want, I can help you with a step-by-step incident response checklist or a secure API key management setup for your stack (AWS/GCP/Azure, GitHub, Node/Python, etc.).