Guide · 2026-10-16

Are Vite environment variables public?

Yes. Any variable that starts with VITE_ and that your code reads through import.meta.env is written into your built JavaScript as plain text. Anyone can read it in the browser.

Why this catches people

The variable lives in a .env file, which feels private. But Vite replaces import.meta.env.VITE_OPENAI_KEY with the actual value at build time. The secret ends up in a file like /assets/index-abc123.js that every visitor downloads.

Variables without the VITE_ prefix aren't exposed, but they also aren't available in your browser code at all. That's the point: a Vite app runs entirely in the browser, so there is no safe place in it for a secret.

What's fine to put in VITE_ variables

What is never fine

The fix

  1. Rotate any secret that was ever in a VITE_ variable on a deployed site.
  2. Move the call that needs it into a small server function: a Vercel or Netlify function, a Cloudflare Worker, or a Supabase Edge Function. Keep the key in that platform's environment settings, without the VITE_ prefix.
  3. Have your app call your function instead of the provider directly.

Check your site in 10 seconds

Free scan for leaked API keys, exposed .env files, link previews, SEO basics and security headers.