Guide · AI API keys · Updated
Is My OpenAI Key Safe in My Frontend? Keep OpenAI, Claude and Gemini Keys Out of Your Lovable, Bolt and v0 App
AI keys are the easiest keys to leak and the fastest to cost you money. If your OpenAI, Anthropic or Gemini key is in browser code, anyone can copy it and use AI on your bill. Here is what OpenAI, Anthropic and Google say, how vibe-coded apps leak these keys, where the key should live, one trap that bites even when the key is hidden, and how to check your live app.
1. The rule: AI keys never go in the browser
Unlike Stripe or Supabase, AI providers have no public key that is safe to show. Every OpenAI, Anthropic and Gemini key is secret.
| Provider | Key looks like | Usual server name | Safe in the browser? |
|---|---|---|---|
| OpenAI | sk-proj-... / sk-... | OPENAI_API_KEY | No |
| Anthropic (Claude) | sk-ant-... | ANTHROPIC_API_KEY | No |
| Google Gemini | AIza... (standard or auth key) | GEMINI_API_KEY | No, not in production |
| Lovable built-in AI | managed for you | LOVABLE_API_KEY | Never in the browser; Lovable keeps it server-side |
- OpenAI: never deploy your key in browsers or mobile apps. Someone can take it and make requests on your behalf, which can mean surprise charges. Route requests through your own backend.
- Anthropic: treat the key like a credit card number. Whoever has it can run up charges on your account. Add it as an encrypted secret, never in code or config files. Using Claude? See the full guide: Is my Anthropic API key safe in my frontend?
- Google Gemini: do not hardcode keys in web or mobile apps, because users can pull them out of client-side code. Use a backend proxy. Google also now rejects unrestricted standard keys, so restrict yours to the Gemini API. Using the same Google project for a map? Keep Gemini off your public Maps key: Is my Google Maps API key safe?
Sources: OpenAI: Best practices for API key safety · Anthropic: API key best practices · Google: Using Gemini API keys
2. How vibe-coded apps leak AI keys
- You paste the key into the chat and the AI writes it straight into a file.
- The AI calls OpenAI from a React component to get a chatbot working fast. That puts the key in the JavaScript every visitor downloads.
- The key goes in a public env var like
VITE_OPENAI_API_KEYorNEXT_PUBLIC_OPENAI_API_KEY. Those prefixes copy the value into browser code. See which env vars end up in the browser.
The chatbot works, so nothing looks wrong. The bill shows up later.
3. Where the key should live (Lovable, Bolt, v0, Cursor)
- Lovable: the built-in AI connector needs no key from you. Lovable creates a
LOVABLE_API_KEYfor the project and runs AI calls through a backend function, so credentials stay server-side. To use your own OpenAI or Claude key, Lovable says to call the provider from a backend edge function with the key stored as a secret. - Bolt and other Supabase apps: make the AI call in a Supabase Edge Function and store the key as an edge function secret.
- v0, Cursor and other Next.js apps: call the provider only from a Route Handler or Server Action. Use an env var without
NEXT_PUBLIC_, likeOPENAI_API_KEY. - Any host: keep keys out of git, use your host's secrets, and use a separate key for each app so one leak means one key to replace.
Leaks often come from an early test build or a quick fix added later. That is why you check the live app, not just your settings.
Sources: Lovable: AI features for your app · Anthropic: Handle keys with secrets · OpenAI: Never commit your key
4. The open AI endpoint trap
Moving the key to the server is step one. But if your AI function takes any prompt from anyone, a stranger can skip your app and call that function directly. They never see your key, yet they still use AI on your bill.
- Require sign-in on the server, not just by hiding a button.
- Limit each user to a fair number of requests per hour.
- Set the model and system prompt on the server. Do not let the browser pick an expensive model.
- Set a spend limit. OpenAI lets you set monthly spend limits with hard enforcement (alerts alone do not stop traffic). Anthropic offers spend limits or careful auto-reload settings. Google suggests billing alerts.
VibeCheck does not call or test your AI endpoints. Check this one by hand, or use the prompts below.
Sources: OpenAI: Monitor usage and set spend limits · Anthropic: Monitor usage and logs · Google: Billing alerts
5. Check your live app in 60 seconds
Only check apps you own or have permission to test.
- Fastest: paste your live link at the top of this page. VibeCheck reads your homepage and the JavaScript files it loads and flags OpenAI (
sk-,sk-proj-), Anthropic (sk-ant-) and Google (AIza) keys. It masks any key it finds. - By hand in Chrome: open your live site, right-click → Inspect, then press Ctrl+Shift+F (Cmd+Option+F on Mac). Search for
sk-proj-,sk-ant-,AIzaandapi.openai.com. - Open your chatbot page and use it once. In the Network tab, look at the request. If it goes straight to
api.openai.com,api.anthropic.comorgenerativelanguage.googleapis.comfrom the browser, your key is in the browser too. It should go to your own server instead.
6. Found a key? Do this now
- OpenAI: rotate the key right away on the API Keys page, then check the Usage page for use you do not recognize.
- Anthropic: delete the key in the Claude Console (API keys page, ⋯ menu, Delete API key), then review the Logs and Usage pages.
- Gemini: make a new key, deploy it, then disable the old one in the Cloud console and check billing and usage.
- Move the AI call to the server (section 3), redeploy, and scan your live site again to confirm the key is gone.
More detail for every key type: I leaked my API key. What do I do now?
Sources: OpenAI: Rotate your key · Anthropic: If your key is compromised · Google: Leak response checklist
7. Copy-paste fix prompts
Paste the matching prompt into Lovable, Bolt, v0, Replit or Cursor. After you deploy, rotate any AI key that was ever in client code.
Search this whole project for sk-proj-, sk-ant-, AIza, OPENAI_API_KEY, ANTHROPIC_API_KEY, GEMINI_API_KEY and GOOGLE_API_KEY. Remove every AI provider key from client-side code and from any NEXT_PUBLIC_, VITE_ or EXPO_PUBLIC_ variable. Move every OpenAI, Anthropic and Gemini call into a server function (Supabase Edge Function, Next.js Route Handler or Server Action) that reads the key from a server-side secret. The browser should only call my own server function. List every key you removed so I can rotate it.
Update my AI server function so only signed-in users can call it: check the user session on the server and return 401 if there is none. Add a per-user limit (for example 20 requests per hour) and return 429 when it is hit. Reject prompts longer than 4,000 characters. Set the model and the system prompt on the server, not from the browser. Show me the changed code.
Switch my AI feature to Lovable's built-in AI connector with the built-in backend, so calls run through a backend function and no provider API key is in my app code. Remove any OpenAI, Anthropic or Gemini key from my frontend files and env vars.
8. Check it for me
Paste your link into VibeCheck. In about 10 seconds it checks the JavaScript your live site sends to visitors for leaked keys (OpenAI, Anthropic, Google, Stripe sk_live_, Supabase service_role and more), checks if your public Supabase key can read open tables, and checks security headers, SEO basics and broken links.
It is a public, read-only check. It never asks for your code, your login or your AI accounts.
Pricing: the problems list is free (just add your email). The $9 fix report gives you a copy-paste fix prompt for every problem found, or get the $29 10-pack (10 fix reports to use any time). No subscription.
No tool can promise your app is 100% secure. VibeCheck catches common, costly mistakes before a stranger does.
9. FAQ
Is it safe to put my OpenAI API key in my frontend?
No. OpenAI says never deploy your key in client-side environments like browsers or mobile apps, because anyone can take it and make requests on your behalf, which can lead to unexpected charges. Send requests through your own backend, where the key stays secret.
Is my Claude (Anthropic) API key safe in browser code?
No. Anthropic compares an API key to a credit card number: if someone gets it, they run up charges on your account. Store it as an encrypted secret on your server or host, never in your code or a public env var.
Can I put a Gemini API key in my web app?
Not in production. Google says not to hardcode Gemini API keys in web or mobile apps, because keys in client-side code can be pulled out by users. Run a backend proxy that makes the call instead, and restrict the key in Google AI Studio or the Cloud console.
Do I need my own OpenAI key in Lovable?
Usually not. Lovable's built-in AI connector manages a LOVABLE_API_KEY for each project and runs AI calls through a backend function, so the key never reaches the browser. If you want your own OpenAI or Claude key, Lovable says to call the provider from a backend edge function with the key stored as a secret.
My key is on the server now. Am I safe?
Mostly, but check your AI function too. If anyone on the internet can call it with any prompt, strangers can still use your AI on your bill. Require sign-in, limit how often each user can call it, cap the prompt size, and set a spend limit with your provider.
How do I check if my live app leaks an AI key?
Paste your live link into VibeCheck for a free scan. It reads the JavaScript your homepage loads and flags OpenAI keys (sk-, sk-proj-), Anthropic keys (sk-ant-) and Google API keys (AIza). You can also open DevTools, press Ctrl+Shift+F (Cmd+Option+F on Mac) and search your loaded files for sk-proj-, sk-ant- and AIza.
More questions? See the VibeCheck FAQ. Related guides: Is my Anthropic (Claude) API key safe? · Is my Gemini API key safe? · How to check if your API key is exposed · I leaked my API key. What do I do now? · Is NEXT_PUBLIC_ safe for API keys? · Is my Stripe key safe? · Is my Resend key safe? · Is my Lovable app safe? · Is my Bolt app secure? · Is my v0 app secure? · Vibe coding security checklist.