Is My Claude API Key Safe in My App?
Short answer: not if it's in your front-end code. Anthropic says to call the Claude API from your own back end, not from code that runs in your users' browsers. If your app calls Claude straight from the page, anyone can pull the key out and use it on your bill. Move the calls to a server and keep the key there.
Check your live app for free
Paste your link. The free summary usually takes under a minute.
See an example report (for example.org) · a real free scan of a test site, so you can see what you get
Why this comes up
You ask Lovable, Bolt, Cursor or a similar tool to "add an AI chat" or "summarize this with Claude." A simple way to make that work is to call Claude right from the page, with the key pasted in. It works on day one. But the page's code is sent to every visitor's browser, and the key goes with it.
What Anthropic says
Anthropic's authentication page is clear: "Call the Claude API from your own back end, not from code that runs in your users’ browsers. Anyone who uses a webpage can read an API key in that page’s code. Typically, your web front end calls your back end, which holds the key and calls the Claude API."
Its help page explains why that matters: "Your API key is a digital key to your account. Much like a credit card number, if someone obtains and uses your API key, they incur charges on your behalf."
(Claude Help Center: API key best practices)
A "back end" just means your own server code (for example a Supabase Edge Function or a server API route) that holds the key and calls Claude for your app. The browser talks to your server, never to Claude with your key.
"But the SDK let me call it from the browser"
Anthropic's TypeScript SDK has a setting called dangerouslyAllowBrowser. Its guide says browser use is "disabled by default to avoid exposing your secret API credentials". If your app sets dangerouslyAllowBrowser to true, your key is in the browser. The guide also says: "Enabling the dangerouslyAllowBrowser option can be dangerous because it exposes your secret API credentials in the client-side code." And: "Any user with access to the browser can potentially inspect, extract, and misuse these credentials."
If you search your code and find dangerouslyAllowBrowser: true, treat that as a sign the key needs to move.
"But my env variable is hidden, right?"
Not always. Putting the key in an environment variable keeps it out of your code files. But in front-end tools like Vite or Next.js, some variables are copied into the code that goes to the browser.
Vite's docs say: "Variables prefixed with VITE_ will be exposed in client-side source code after Vite bundling." They also say: "VITE_* variables should not contain sensitive information such as API keys. The values of these variables are bundled into your source code at build time." (Vite: Env Variables and Modes)
Next.js lists this as a built-in feature: "Bundle environment variables for the browser by prefixing with NEXT_PUBLIC_". And: "these public environment variables will be inlined into the JavaScript bundle during next build." (Next.js: How to use environment variables)
If the page calls Claude directly, the key has to be in the browser for that to work, so it's public no matter where you stored it.
How to check your app
- Ask your AI builder. Paste this:
Find every place my app uses an Anthropic or Claude API key. For each one, tell me: is the key used in code that runs in the browser, or only in server code (an Edge Function or server API route)? Check environment variables that start with VITE_ or NEXT_PUBLIC_ too, and tell me if dangerouslyAllowBrowser is set anywhere. Don't change any code yet.- Run the free scan. Paste your URL in the box at the top. It looks for keys that look like Anthropic keys in the HTML tags on the page (including tag attributes), the inline scripts on that page, and up to 15 script files from your own site. More on what it can and can't see is below.
How to fix it
If the key is in your front-end code:
- Move the Claude calls to a server. Paste this:
Move all Anthropic (Claude) API calls out of my front-end code into a server function (a Supabase Edge Function or a server API route). Store the Anthropic key as a server-only secret, not in any VITE_ or NEXT_PUBLIC_ variable, and remove dangerouslyAllowBrowser. Have my app call my server function instead, and only let logged-in users call it. Then show me that no Anthropic key is left in any file that runs in the browser.- Treat the old key as leaked. Make a new key, update your server secret, check the app works, then turn off the old one. Anthropic says to "disable or delete any key you suspect has leaked." On the API keys page in the Claude Console, "Disable is reversible", while "Delete is permanent". (Claude Docs: Authentication)
- Watch your usage and set limits. Anthropic recommends "regularly reviewing the Logs page" and "the Usage page" in the Console. It says spend limits and rate limits "act as a safeguard against unexpected usage due to leaked keys or errant scripts." If your account uses auto-reload, Anthropic says: "Carefully consider auto-reload limits." (Claude Help Center: API key best practices) See also How do I stop a surprise bill on my vibe-coded app?
Things to watch for
- Don't put the key in Git. Anthropic says: "you must add your
.envfiles to your source control ignore file (e.g.,.gitignorefor git) to prevent inadvertently distributing sensitive information publicly." See also Can anyone download your .env file? - Use separate keys. Anthropic suggests "different API keys for development, testing, and production environments" so that if one leaks, you can "quickly disable just that use case and limit any potential damage."
- Your server function needs limits too. Once Claude runs through your server, anyone who can reach that function can still run up costs. Require a login and limit how often each user can call it. See Limit how often people can try to log in.
What the rooGBotVC scan checks
Paste your URL in the box at the top. The scan reads the HTML tags on the page you scan (including tag attributes), the inline scripts on that page, and up to 15 script files from your own site.
- If it finds a key that looks like an Anthropic key, it shows "Anthropic API key exposed in public code" (critical). It looks for keys that start with
sk-ant-apiorsk-ant-admin, followed by two digits and a long string. Found keys are shown with most of the key hidden.
What the scan can't do:
- It doesn't run your JavaScript, so a key that only shows up after the page runs, or that is loaded from another site, may be missed.
- If your Anthropic key looks different from that pattern, the scan may not catch it.
- It can't see your Claude Console settings, so it can't tell whether a key is disabled, how much it has been used, or what limits you have set.
- It never uses or tests any key it finds.
- It doesn't test logins, rate limits, billing or RLS.
Related reading
- Exposed API keys: what to do when any key leaks.
- Is my OpenAI API key safe in my app?: the same idea for an OpenAI key.
- Is my Gemini API key safe in my app?: the same idea for Google's Gemini key.
- Is my Grok (xAI) API key safe in my app?: the same idea for an xAI Grok key.
- How do I stop a surprise bill on my vibe-coded app?: budgets and alerts.
- Are your source maps public?: another way your code can show more than you think.
The bottom line
A Claude key in front-end code is a public key, and Anthropic says to call the API from your own back end. Move Claude calls to your own server, remove dangerouslyAllowBrowser, make a new key, turn off the old one, and keep an eye on your usage and limits. Then paste your URL in the box at the top to check what your app shows the public.
Related guides
This is an automated, surface-level check of what your site shows the public. It is not a full security audit.