AppInspected

Fix guides

Your Anthropic API key is in your frontend. Anyone can use Claude on your bill.

Last reviewed October 25, 2026 against the providers' current documentation.

The short version

Create a new key in the Claude Console, put it only in server code, and have your app call that server instead of the Claude API. Then delete the old key, and set a monthly spend limit so a future leak can't run up a large bill. If the key starts with sk-ant-admin, it's an Admin API key and can manage your whole organization: delete it first.

Why it matters

Anthropic's own help center compares an API key to a payment credential: anyone who has it can run requests that are billed to your account. Every file your site sends to the browser can be read with the developer tools in seconds, and people scan public sites for AI keys because they can use or resell the access. Anthropic's TypeScript SDK refuses to run in a browser by default, with the warning that it "risks exposing your secret API credentials to attackers"; if your code sets dangerouslyAllowBrowser: true and holds your own key, that's exactly what happened. An Admin API key (sk-ant-admin01-…) is worse: Anthropic's docs say Console admin keys carry full access to the Admin API, which manages organization members, workspaces and API keys.

Fix it, in this order

  1. Delete the leaked key

    In the Claude Console, open Settings → API keys, find the key, and choose Delete API key from its menu. Anthropic's docs describe Disable as reversible and Delete as permanent; for a key that has been public, delete it. An sk-ant-admin01- Admin API key can only be managed by an organization admin in the Console; ask one to delete it right away.
  2. Create a new key and keep it on a server

    Click Create key, give it a name and an expiration, and copy it straight into a server-only secret named ANTHROPIC_API_KEY (the name Anthropic's SDKs read by default). Anthropic recommends separate keys for development, testing and production, so one leak can be switched off without taking down the rest. Never put it in a VITE_, NEXT_PUBLIC_ or EXPO_PUBLIC_ variable: those are copied into your browser JavaScript.
  3. Add a small server endpoint

    Create one server-side route that receives the user's message, calls Claude with the key from the server secret, and returns only the answer: a Next.js Route Handler, a Supabase Edge Function (store the key with supabase secrets set ANTHROPIC_API_KEY=… and read it with Deno.env.get()), or a Cloudflare Worker. Keep the model name, max_tokens and the system prompt on the server, so the browser can't change them.
  4. Protect that endpoint

    Require a logged-in user, limit how many requests each user can make per minute, and accept only the inputs your feature needs. An open endpoint that forwards anything to Claude is a free proxy for whoever finds it, which costs you the same as a leaked key.
  5. Remove the browser setup

    Point the frontend at your endpoint, remove the key from every client file, and delete dangerouslyAllowBrowser: true and any anthropic-dangerous-direct-browser-access header from browser code. Deploy and confirm the feature still works.
  6. Cap spending and watch usage

    On the Console's Billing page, under Spend limits, set a monthly limit below your tier's cap; Anthropic's docs say requests stop with an error once it's reached. For a stricter cap on one app, give it its own workspace and set that workspace's Spend limits under Settings → Workspaces (not possible on the Default Workspace). Then check the Console's usage and logs for traffic that doesn't match your app.

Or ask your AI tool to do it

Paste this into Lovable, Bolt, Cursor, Claude Code or whichever tool built your app. Review what it changes before you deploy.

My Anthropic (Claude) API key is exposed in frontend code. Create a server-side endpoint that calls the Claude API using a key read from a server-only environment variable ANTHROPIC_API_KEY. Keep the model, max_tokens and system prompt on the server. The endpoint must require an authenticated user, rate-limit each user, accept only the specific inputs the feature needs, and return only the text the UI shows. Update the frontend to call this endpoint instead of api.anthropic.com, remove the key from all client code and from any VITE_, NEXT_PUBLIC_ or EXPO_PUBLIC_ variables, and remove dangerouslyAllowBrowser and the anthropic-dangerous-direct-browser-access header from browser code. Finally, remind me to delete the old key in the Claude Console and set a spend limit.

How this happens

The fastest way to demo a Claude feature is to call the API straight from the page. The SDK blocks that, the error message names dangerouslyAllowBrowser, and an AI coding tool asked to make the error go away sets it to true. Or the key goes into a VITE_ or NEXT_PUBLIC_ variable because a plain one came out empty in the browser. Either way the demo works, and the key ships with it.

Check that it's really fixed

After you deploy, run the free check. It reads your live site the way an attacker would and tells you if any secret key is still visible.

Topic check: Exposed API key checker

Find the other leaks before someone else does

The free check reads your home page and its scripts. The website security report goes through up to 30 pages and 40 JavaScript files, plus .env and .git files, security headers, cookies and CORS, domain and email records, and libraries with known vulnerabilities. Every finding comes with the fix for your host and a prompt for your AI tool.

$19 once, including 20 runs over 30 days so you can fix things and check again.

Get the report, $19 See an example report

Example report header: a score out of 100, findings by severity, Download PDF and Email me this report.

Questions

How do I know it's an Anthropic key?

Claude API keys start with sk-ant-api (for example sk-ant-api03-…) and Console Admin API keys start with sk-ant-admin01-. Our free check flags both as critical. It shows only the start of the key and never tries to use it.

Isn't dangerouslyAllowBrowser fine if I hide the key?

No. If the browser sends the key, anyone can read it from the network tab, however it's split or encoded. The option only makes sense when the key isn't yours to lose, for example an internal tool for trusted colleagues, or an app where each user pastes in their own key.

Will Anthropic shut the key off for me?

Only in some cases. Through GitHub's secret scanning partner program, Anthropic says it automatically deactivates Claude API keys found in public GitHub repositories and emails the owner. A key in your live website's JavaScript isn't covered by that, so delete it yourself.

I deleted the key from my code. Is that enough?

No. Old copies of your JavaScript stay in browser caches, CDN caches and archives, and the key keeps working until you delete it in the Console.

Is a spend limit enough on its own?

No, but it limits the damage. Anthropic's docs say a spend limit you set stops requests once it's reached, so someone using a leaked key can still use up your budget and take your own app offline until the next month. Fix the leak first, then keep the limit as a safety net.

Does this apply to OpenAI and other AI keys?

Yes, the same steps work for every AI provider. See OpenAI API key in your frontend and Google API keys (Gemini).

Sources

Related guides