ShipWatchFree scan

Anthropic API key exposed in your frontend: how to check, revoke and fix it

You asked your AI builder to "add a Claude chat" and it worked on the first try. Then you noticed the code says dangerouslyAllowBrowser: true, or you searched your site's JavaScript and found a string starting with sk-ant-.

Short answer: if your own Anthropic key is in code that runs in the browser, it is public. Anyone who opens DevTools can copy it and send requests that are billed to your Claude Console account. Revoke it, make a new one, and move the Claude call to a server function.

Unlike some Google Maps or Firebase keys (see our Google key guide), there is no "restricted browser key" version of an Anthropic API key. Anthropic's help center compares the key to a credit card number: whoever has it can run up charges on your behalf.

Why the flag is called "dangerously"

Anthropic's official TypeScript SDK refuses to run in a browser by default. Its own source code says client-side use "risks exposing your secret API credentials to attackers." To get past that refusal, you have to pass dangerouslyAllowBrowser: true, which also makes the SDK send the anthropic-dangerous-direct-browser-access: true header so the browser is allowed to call the API directly.

That option exists for a narrow case: bring-your-own-key apps, where each visitor pastes their own key and it never touches your servers. It was not built for shipping your key to every visitor.

AI coding tools sometimes add the flag to make an error message go away. The app works, the error disappears, and the key ships.

What you see in the codeIs it a leak?
new Anthropic({ apiKey: import.meta.env.VITE_ANTHROPIC_API_KEY, dangerouslyAllowBrowser: true })Yes. VITE_ variables are baked into the public bundle.
NEXT_PUBLIC_ANTHROPIC_API_KEY used anywhereYes. NEXT_PUBLIC_ means shipped to the browser.
A literal sk-ant-... string in a React componentYes.
fetch("https://api.anthropic.com/v1/messages", ...) from browser code with your key in the x-api-key header (plus anthropic-dangerous-direct-browser-access)Yes, same thing without the SDK.
dangerouslyAllowBrowser: true with a key the visitor typed in (stored only in their browser)Not your key, so not your leak. Still tell users where their key goes.
Browser calls your endpoint (/api/chat, a Supabase Edge Function), and that server code calls Anthropic with process.env.ANTHROPIC_API_KEY / Deno.env.get(...)No. This is the safe pattern.

Step 1: Check what your live app actually ships

Check the deployed site, not just your source. The build is what visitors download.

  1. Open your live app in Chrome, press F12, go to Sources (or Network and reload).
  2. Press Ctrl+Shift+F (Cmd+Option+F on Mac) to search all loaded files.
  3. Search for sk-ant-, then dangerouslyAllowBrowser, then anthropic-dangerous-direct-browser-access, then api.anthropic.com.

Or run the free ShipWatch scan: it looks for Anthropic API keys (plus OpenAI, Stripe, AWS, Google and Supabase service_role keys) in the page HTML and in up to 25 JavaScript files the page links to, and shows any hit masked.

What the scan can't tell you: whether the key is still active, how much it has been used, or whether someone else already copied it. It only sees what your live page ships. A clean scan is not a guarantee.

Step 2: Revoke the key (before you fix the code)

Fixing the code doesn't un-publish a key. Copies of your old bundle may already exist, so treat any key that shipped as burned.

  1. Sign in to the Claude Console and open the API keys page (platform.claude.com/settings/keys).
  2. Click the menu (three dots) next to the exposed key and choose Delete API key.
  3. Create a new key, and store it only as a server-side secret (see Step 3). Don't paste it back into frontend code.
  4. Open the Usage (platform.claude.com/usage) and Logs (platform.claude.com/logs) pages and look for traffic you don't recognize.

Your Claude feature will stop working until the new key is deployed server-side. That's expected and much cheaper than leaving the old key live. For the full order of operations, see how to rotate a leaked API key.

Step 3: Move the Claude call to the server

The browser should call your endpoint. Only your server talks to Anthropic.

Lovable / Bolt (Supabase Edge Function): add ANTHROPIC_API_KEY as a Supabase secret, and call Anthropic from an Edge Function that reads Deno.env.get("ANTHROPIC_API_KEY"). The frontend calls the function, never Anthropic.

Next.js / v0 (Vercel): put the key in Vercel's environment variables without the NEXT_PUBLIC_ prefix, and call Anthropic from a Route Handler (app/api/chat/route.ts) or a Server Action.

Replit / Cursor projects with a backend: keep the key in Replit Secrets or a server-only .env that is in .gitignore, and make the call from your server code.

On the server, both official SDKs read ANTHROPIC_API_KEY from the environment by default, so you don't need to pass the key in code:

// TypeScript / Node (npm install @anthropic-ai/sdk), server code only
import Anthropic from '@anthropic-ai/sdk';
const client = new Anthropic(); // reads process.env.ANTHROPIC_API_KEY
const message = await client.messages.create({ model, max_tokens: 1024, messages });

# Python (pip install anthropic)
from anthropic import Anthropic
client = Anthropic()  # reads the ANTHROPIC_API_KEY environment variable
message = client.messages.create(model=model, max_tokens=1024, messages=messages)

Copy-paste prompt for your AI builder:

Move every Anthropic/Claude API call out of the browser. Remove dangerouslyAllowBrowser and any VITE_/NEXT_PUBLIC_ Anthropic variables. Create a server-side endpoint (Supabase Edge Function / Next.js route handler) that reads ANTHROPIC_API_KEY from server secrets, checks the user is signed in, limits request size, and calls Anthropic. Update the frontend to call that endpoint instead. Make sure no sk-ant- string appears in the built JavaScript.

Two extras that matter once the call is on the server:

What about GitHub?

If an Anthropic key is pushed to a public GitHub repo, GitHub's secret scanning reports it to Anthropic, which automatically deactivates the key and emails the account owner (Anthropic has been a GitHub secret scanning partner since August 2024). GitHub's Oct 13, 2026 changelog added two new Anthropic key detectors and turned push protection on for them by default, so repositories with secret scanning enabled block commits containing those keys.

That safety net covers repositories. It doesn't cover a key sitting in your live site's JavaScript bundle, which is where many AI-built apps leak keys. That's the gap the outside-in check in Step 1 covers.

Quick checklist

Checked against Anthropic's SDKs (anthropic-sdk-typescript, anthropic-sdk-python), Claude API docs and help center, and GitHub's changelog on Oct 23, 2026.

FAQ

Is it ever OK to call the Claude API from the browser?
Only when each visitor brings their own key and it never touches your servers. That is the case dangerouslyAllowBrowser exists for. Your own key in browser code is always a leak.
What does an Anthropic API key look like?
Standard API keys start with sk-ant-api03- and Admin API keys start with sk-ant-admin01-. Search your live JavaScript for sk-ant- to catch both.
Where do I revoke a leaked Anthropic key?
In the Claude Console, on the API keys page (platform.claude.com/settings/keys): open the menu next to the key and choose Delete API key. Then create a new key and store it only as a server-side secret.
Will GitHub catch a leaked Anthropic key?
In public repositories, GitHub secret scanning reports Anthropic keys to Anthropic, which deactivates them and emails the owner. That does not cover a key shipped in your live site's JavaScript bundle.
Does the free scan tell me if my key is still active?
No. ShipWatch only sees what your live page ships. It can't tell whether a key works, how much it was used, or whether someone already copied it.

Scan your app free in 30 seconds

Paste your live URL for a plain-English report with fix prompts. If you keep shipping, weekly monitoring re-checks it: Solo $19/mo or Pro $49/mo.

Scan my app free