Where do I put my API key in Lovable so nobody can see it?

By Arif Khan, AIVolve LLC · Updated November 30, 2026

"I need to add my OpenAI or Stripe key to my Lovable app. Where does it go so people visiting my site cannot see it? And what if I already pasted it into the code?"

Short answer: Put private keys in Lovable's Secrets, never in your app's code or in a VITE_ variable. Lovable's docs say secrets are encrypted, read by your app's server-side code (edge functions in older apps, server functions in newer ones) and never reach the browser. The easiest way is to ask Lovable to build the feature and to ask you for any keys it needs, then type the key into the secure Add secret form it shows. Only keys made for the browser, such as your Supabase publishable key or a Google Maps browser key, belong in frontend code. If a private key was ever in your app's code, treat it as leaked: create a new key at the provider, store the new one in Secrets, and turn the old one off.

Why the code is the wrong place

Part of your app runs in your visitors' browsers, and anyone can read the code there. Lovable's security guide says secrets stored in frontend code are visible to users and should be considered compromised. A VITE_ variable is no hiding place either: Lovable's docs say anything prefixed with VITE_ is embedded into the browser code when the app is built.

Which keys are private, and which are fine in the browser

Key Where it goes Why
Stripe secret key, OpenAI or Anthropic API key, Resend key, other service credentials Secrets Anyone can read browser code, and these keys can spend money or reach data.
Supabase service role key Nowhere you type it. Lovable already puts it in your edge function environment as SUPABASE_SERVICE_ROLE_KEY It skips your row level security rules, so it must never reach the browser.
Supabase URL and publishable (anon) key .env, as VITE_ values Lovable says these are safe to be public. Your row level security rules decide what they can reach.
Google Maps Platform browser key, and other keys a provider designs for browsers Frontend code, restricted to your domains The provider expects them to be public, and the domain restriction limits who can use them.
LOVABLE_API_KEY Lovable manages it It powers built-in AI. If you think it was exposed, use Rotate in Secrets.

Not sure which kind of Supabase key you have? Our guide on the Supabase anon key vs the service_role key explains how to tell.

Three safe ways to add a key

  1. Let Lovable ask for it. Describe the feature and say "Ask me for any API keys you need." Lovable shows an Add secret form in the chat. Before you paste, check the secret name (for example STRIPE_SECRET_KEY), read Lovable's message about what it needs the key for, and copy the value from the provider's dashboard. Lovable's docs recommend this form over typing the key into the chat, so the key stays out of your chat history.
  2. Add it yourself. Go to More → Settings → Secrets and select Add secret. Secrets are write-only: after you save one, nobody can view its value again in Lovable, only replace or delete it. In newer apps (created from May 13, 2026, on TanStack Start), a changed secret reaches your published app only after you publish again.
  3. Use a connector. For a service in Lovable's connector catalog, or a custom connector a workspace admin creates, the key is stored encrypted in Lovable's connector gateway, outside your app, and added to requests on the server. It does not appear in your project's code or chat.

If you paste a key into the project chat anyway, Lovable detects it, saves it as a project secret and offers to set up a connector for that tool.

Check whether a key is already exposed

If a private key was in your code: five steps

  1. Create a new key at the provider and turn the old one off. Do this first. Lovable treats a key in frontend code as compromised, and GitHub's docs say the first step for a leaked secret is to revoke or rotate it.
  2. Store the new key in Secrets, using the Add secret form, not the chat.
  3. Ask Lovable to move the call to the server. The frontend should call your own edge function or server function, which reads the secret. Then ask it to remove the old key from every file.
  4. Publish. Your live site keeps showing the version you last published, old key included, until you publish again.
  5. Check the provider's dashboard for usage you do not recognize since the key was exposed.

If your code is on GitHub, the old key is still in your git history after you delete it from the code. GitHub's docs say that once the secret is revoked or rotated it can no longer be used, and that may be enough without rewriting the history. One more trap: do not add .env to .gitignore in a Lovable project. Lovable's docs say it needs .env committed for builds, which is fine as long as .env holds only public VITE_ values.

A prompt for Lovable (Chat mode)

Check this project for API keys and secrets. Do not change any code yet. 1. List every API key, token or secret that is written in the frontend code, in a VITE_ variable or in .env. For each one, show only the variable name, the file and the service it belongs to. 2. For each one, tell me whether it is meant to be public (like the Supabase publishable key) or private. 3. For each private one, explain how you would store it in Secrets and call the service from server-side code instead. Never print a key or secret value. Wait for my approval before changing anything.

How to check you are done

  1. The advanced checks show no findings under Keys and passwords.
  2. The leaked keys checker finds no private key in your project folder.
  3. More → Settings → Secrets lists each private key by name, and none of them is a VITE_ value.
  4. Every key that was ever in your code has been replaced at the provider, and the old one no longer works.
  5. You published after the change, and the feature that uses the key still works on the live site.

FAQ

Is it safe to have my Supabase key in my Lovable app's code?+

The Supabase URL and publishable (anon) key, yes. Lovable's docs say these VITE_ values are safe to be public, and your row level security rules decide what they can reach. The service role key is different: it skips those rules, so it must never be in your app's code.

Can I see a secret's value after I save it in Lovable?+

No. Secrets in Lovable are write-only. You can replace or delete a secret, but never read its value back. If you lose a key, generate a new one at the service that issued it.

Should I put my API key in Secrets or in .env?+

If the value must stay private, such as a payment key, an AI provider key or a service credential, use Secrets. If it is a VITE_ value that is safe to be public, it belongs in .env. Lovable rejects VITE_ names in Secrets for this reason.

I pasted my API key into the Lovable chat. Is that a problem?+

Lovable detects a pasted key, saves it as a project secret and offers to set up a connector for that tool. Its docs still recommend the Add secret form, so the key stays out of your chat history. If the same key was ever written into your app's code, create a new key at the provider.

Do I need a new key if I already deleted the old one from my code?+

Yes. Lovable says secrets in frontend code should be considered compromised, and your live site keeps the old code until you publish again. If the code is on GitHub, the key also stays in your git history. Create a new key at the provider and turn the old one off.

Want a second pair of eyes?

A key in the wrong place is often one of several loose ends in an app that looked finished. Our free X-ray takes about 2 minutes and needs no code or passwords. You get a plain-English verdict, and an AIVolve developer reviews every one within 1 business day. Get a free X-ray →

Related: Supabase anon key vs service_role key: which one is safe in your app? · Did my repo leak API keys? Free checker · Is my Lovable app secure? The 15-minute check before real users · Why did the AI feature in my Lovable app stop working?

Written by Arif Khan, AIVolve LLC. VibeCoderSOS isn't affiliated with Lovable, Supabase or GitHub. Based on Lovable's documentation (Secrets, integrating any API, edge functions, security checks, the Security view, security best practices, publishing) and GitHub's documentation on removing sensitive data from a repository, checked on November 30, 2026. We have not tested these steps on a live Lovable project, and Lovable changes its product often, so follow the text in your project if it differs.

Need help?

Not sure where your keys ended up? A free X-ray tells you what works, what only looks done and what to fix first.

Get a free X-ray →