How to rotate an OpenAI API key after a leak
If an OpenAI key landed in a public repo, gist, paste, screenshot, or chat log, treat it as burned. OpenAI’s own guidance: protect keys, rotate when concerned, and use spend limits so a stolen key cannot run unbounded (API key safety, account security).
Safe and Secure is the secrets twin of View Spend: soft helpers for solo builders, not a security suite. Your secrets. Your stack.
Rotation checklist
- Open platform.openai.com/api-keys and delete / revoke the exposed key.
- Create a new project key with the narrowest scope you need; prefer keys with an expiration when available.
- Update every consumer: local
.env, hosting env vars, GitHub Actions secrets, serverless configs, teammate machines. - Confirm the old key returns unauthorized; smoke-test the new key on a non-prod path first.
- Review the Usage page for the exposure window for unexpected traffic.
- Set or tighten spend alerts and hard spend limits so a future leak cannot become an unbounded bill.
Prevention that actually sticks
- Never commit real keys — use
.env.examplewith placeholders - Enable GitHub push protection for your user / repos
- Add a pre-commit secret scanner (Gitleaks / similar)
- Separate personal experiment keys from production keys
Where Safe and Secure helps
Inventory the keys you actually keep. Planned watch on paste sites, GitHub, package registries, and public logs. When a match shows up: alert, then rotate where the provider API allows. Honest limits: not a guarantee; not GitHub Advanced Security; not a full enterprise desk like GitGuardian’s paid platform.
Also see: leaked API key on GitHub · committed .env · GitGuardian alternative for solo builders
FAQ
Will OpenAI disable a leaked key automatically?
OpenAI states that when it detects an API key on the public internet (or leaked inside an app store), the key can be disabled. Still revoke and rotate yourself — do not wait on detection.
Should I rewrite git history?
Only after the key is revoked. History rewrite does not remove forks, caches, or mirrors. Revocation is the essential step.
Does Safe and Secure rotate OpenAI keys for me?
Planned flow is detect → alert → rotate where the provider API already allows it. Until that path is live for your account, rotate in the OpenAI dashboard yourself.
Is this the same as View Spend?
No. View Spend tracks LLM spend with read-only usage keys. Safe and Secure is the secrets twin — inventory, leak hygiene, and planned monitoring.
CTA
Safe and Secure — soft helpers for your stack, not a security suite. Your secrets. Your stack. See the product page or email hello@myviewspend.com. No invented pricing on this page.