Prompt
What should I use instead of storing API keys in env files?
Latest observation
Oct 25, 2026
OpenAI APIWeb search: off
A better alternative is to use a secrets manager rather than .env files for anything beyond local development.
Good options
- Cloud-native secrets managers
- AWS Secrets Manager / SSM Parameter Store
- Google Secret Manager
- Azure Key Vault
- Dedicated tools
- HashiCorp Vault
- Doppler
- 1Password Secrets Automation
- Infisical
- For local development
- Use a local
.envfile only for dev, but keep it out of git and never use it for production
- Use a local
Recommended pattern
- Store secrets in a secrets manager
- Inject them into the app at runtime
- Use short-lived credentials where possible
- Rotate secrets regularly
- Give each service the minimum permissions it needs
If you want a simple upgrade path
If you’re currently using .env files, a practical next step is:
- Keep
.envonly for local dev - Move production secrets to a secrets manager
- Load them through your deployment platform or app startup
- Audit access and rotate keys
Important note
If the “API key” is for a service you control, consider replacing it with:
- OAuth tokens
- Service accounts
- Signed requests
- Short-lived tokens from an auth broker
If you tell me your stack, I can recommend the best option for your setup.