Critical severity

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

  1. 01Search your bundle for `sk-ant-`.
  2. 02Anthropic Console → Settings → API keys → check recent usage.
  3. 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.

Scan your site for this and 50+ other issues

Free scan. Results in 60 seconds. No account required.