Prompt
What is the easiest way to store API keys for an app?
Latest observation
Nov 9, 2026
OpenAI APIWeb search: off
The easiest and safest way is usually:
-
Store API keys in environment variables
- Example:
OPENAI_API_KEY=... - Your app reads them at runtime, not from source code.
- Example:
-
Keep them out of version control
- Add
.envfiles to.gitignore - Never commit secrets to GitHub
- Add
-
Use a secret manager in production
- Examples: AWS Secrets Manager, Google Secret Manager, Azure Key Vault, HashiCorp Vault
- These are better than plain config files on servers
-
Use a
.envfile for local development- Convenient for developers
- Load it with tools like
dotenv - Example:
API_KEY=your_key_here
-
Rotate keys if exposed
- If a key leaks, revoke it and replace it immediately
Rule of thumb
- Local dev:
.env - Production: secret manager or platform environment variables
- Never: hard-code keys in your codebase
If you want, I can show the best approach for your stack (Node, Python, React, mobile, etc.).