OpenAI API key exposed in your frontend? Do this now
Bots scan public websites and GitHub for AI API keys around the clock. A leaked OpenAI or Anthropic key can run up a large bill within hours.
Step 1: revoke the key
OpenAI: platform.openai.com → API keys → delete the key. Anthropic: console.anthropic.com → API keys → disable it. Then create a new key and set a monthly spend limit.
Step 2: move the call to a server
Your frontend should call your own endpoint, and only the server talks to OpenAI. In Next.js that is a route handler:
// app/api/chat/route.ts
export async function POST(req: Request) {
const { message } = await req.json();
const r = await fetch("https://api.openai.com/v1/chat/completions", {
method: "POST",
headers: {
Authorization: `Bearer ${process.env.OPENAI_API_KEY}`,
"Content-Type": "application/json",
},
body: JSON.stringify({ model: "gpt-4o-mini", messages: [{ role: "user", content: message }] }),
});
return Response.json(await r.json());
}Step 3: make sure it's really gone
Don't prefix the variable with NEXT_PUBLIC_ or VITE_, check that the old key isn't in your Git history, and redeploy. Then scan the live site again to confirm.
Check your app now. Free, no signup, under a minute.
Scan your appMore guides: Is my Lovable app secure? A 5-minute check · How to check if Supabase RLS is enabled (and fix it) · Firebase test mode rules: how to tell if your database is open · How to check if your website leaks API keys · Security checklist for apps built with Bolt, Cursor, v0 and Replit · Is this Claude skill or MCP server safe to install? A 5-minute check