How to keep API keys secret when you vibe code
Leaked keys are the most common and most expensive beginner mistake. Bots scan public GitHub repositories continuously, and a leaked paid-API key can run up a bill within hours.
The rules
- Keep keys in a
.envfile and add.envto.gitignorebefore the first commit. - Use a separate key per project and per environment, with only the permissions it needs.
- Never put a secret in code that ships to the browser. Variables prefixed
NEXT_PUBLIC_orVITE_are exposed to every visitor. - Do not paste real keys into AI chats. Use placeholders and let the tool read your
.envlocally if it must. - Check
git statusbefore every commit so a stray env file is not added.
If a key has leaked
- Revoke or rotate the key at the provider immediately. This is the fix; the rest is cleanup.
- Deleting the file in a later commit does not help: the key stays in git history.
- Check the provider’s usage page for activity you did not cause.
- Make the repository private if it was public, and add a secret scanner such as
gitleaksto your workflow.
See the full security checklist for what else to verify before launch.
Want the whole checklist?
Vibe101 is an interactive checklist, 11 chapters from idea to launch. The Security first chapter is free.
Published by the author of Vibe101, a paid checklist. This is general information, not legal advice or a security audit.