How to fix an exposed Anthropic / Claude API key
Your Anthropic API key (starts with `sk-ant-`) is in your client bundle. Key scrapers find these as fast as OpenAI keys and use them to run Claude on your bill. Fix: revoke in Anthropic Console, set a usage limit, and move every Claude call to server-side code. Use the Vercel AI Gateway or your own Route Handlers so the key never reaches the browser.
Why it matters
Claude billing is not capped by default. A leaked key running Opus models costs hundreds of dollars per hour. Same threat profile as an OpenAI leak.
How to check
- 01Search your bundle for `sk-ant-`.
- 02Anthropic Console → Settings → API keys → check recent usage.
- 03Console → Usage → look for unexpected spikes.
Or let SafeToShip check it for you in 60 seconds:
How to fix it
Anthropic Console
Settings → API Keys → Revoke leaked key. Then Settings → Billing → set a monthly limit.
Next.js + AI SDK
Use the AI SDK and call Claude via the Gateway.
// app/api/chat/route.ts
import { streamText } from 'ai';
export async function POST(req: Request) {
const { messages } = await req.json();
const result = streamText({
model: 'anthropic/claude-haiku-4-5-20251001',
messages,
});
return result.toTextStreamResponse();
}AI prompt
Copy-paste into your AI tool
Paste this prompt into Cursor, Lovable, Bolt, v0, or Claude Code and it will walk through the fix for your specific codebase.
My Anthropic API key (sk-ant-) is exposed in my frontend. Revoke it in Anthropic Console, then migrate my Claude calls to a server-side route handler using the Vercel AI SDK. Set a monthly usage limit in Anthropic billing settings.FAQ
Frequently asked questions
- Should I just use a different provider?
- The provider does not matter — all LLM keys have the same threat model. The fix is server-side routing, not switching vendors.
Related fix guides
Fix these too
Hardcoded API key in JS
Any secret in your client bundle is public. Here is how to find them, rotate them, and move the calls server-side.
Read moreExposed OpenAI API key
OpenAI keys in client code get drained fast — attackers use them to run expensive models on your bill. Here is how to lock it down.
Read moreExposed .env file
An exposed .env file is a critical leak — it contains API keys, database URLs, and secrets. Here is why it happens in vibe-coded apps and how to lock it down.
Read moreFree tools
Check this yourself
Platform guides
Building on these platforms?
Next.js security
Next.js is the most popular React framework, but even experienced developers miss security headers and accidentally expose server files in production.
Read moreLovable security
Lovable makes it easy to ship fast, but AI-generated backends often ship with open Supabase tables and leaked API keys. Scan your Lovable app before your users find out.
Read moreCursor security
Cursor helps you write code faster with AI, but AI-assisted code can introduce subtle security issues. Missing headers, exposed files, and insecure cookies slip through easily.
Read moreScan your site for this and 50+ other issues
Free scan. Results in 60 seconds. No account required.