Can I hide an API key by putting it in a frontend environment variable?
No. Any value embedded into client-side JavaScript can be recovered by a visitor. Frontend environment variables are configuration, not secret storage.
Pre-launch guide
A frontend bundle is public by design. Obscuring a key in minified JavaScript does not protect it. This guide explains how to identify a real exposure, contain it quickly, and avoid shipping privileged credentials in browser code again.
Use VibeTester for a fast independent check of buttons, browser errors, mobile overflow, and public secrets.
Scan my appIf a credential reaches a browser, assume a motivated visitor can retrieve it. Some providers intentionally expose public identifiers, but private provider keys, unrestricted tokens, service-role credentials, and cloud access keys should never be in the frontend.
Review inline scripts, downloaded JavaScript bundles, configuration endpoints, and source maps if they are public. Search for provider prefixes, environment variable names, and terms such as secret, token, key, service role, or private. Scan the deployed domain instead of relying only on repository search.
Deployment mistakes can expose files that were never meant to be served. Check common sensitive paths such as .env and .git/config, and verify hosting configuration does not publish build artifacts, backups, or source files unintentionally.
If you find a real secret, revoke or rotate it immediately. Removing it from a bundle stops future exposure, but it does not invalidate a value that may already have been copied. Review provider logs, spending, and access history where available.
The safe pattern is browser to your server-side endpoint to provider. Keep provider secrets in server-side environment variables, authenticate and authorize the caller, validate input, and rate-limit expensive operations. Do not solve the problem by merely renaming or encoding the client-side variable.
Use separate public and server-only configuration names, scan builds before deployment, restrict keys at the provider when possible, and teach contributors that a frontend environment variable is public. Restrictions reduce blast radius but do not turn a secret into a public value.
No. Any value embedded into client-side JavaScript can be recovered by a visitor. Frontend environment variables are configuration, not secret storage.
Rotate or revoke it immediately, review provider activity, remove it from browser code, and move the privileged request to a server-side environment.
Some providers issue public identifiers for browser use. Confirm the key type in the provider documentation and ensure it cannot perform privileged actions or access private data.