Skip to content

My OpenAI key leaked. What do I do?

Short answer

Revoke the key at platform.openai.com/api-keys (revocation takes effect within seconds), create a new one in a server-side env var, then check Usage for spend you didn't make. Anyone holding an OpenAI key can bill model usage to your account. If OpenAI already emailed that the key was leaked, it's disabled. Still replace it and remove it from your code.

Last updated 2026-11-25 · Reviewed by ProofForge

Is it this key?

Format: sk- (project keys look like sk-proj-…)

Blast radius: Anyone with the key can call any model your project allows and bill it to you, and can read files, assistants or other stored data the key's permissions reach.

The first 10 minutes

WhenDoHow
0–2 minRevokeOpen platform.openai.com/api-keys and delete the leaked key.
2–4 minReplaceCreate a new key (restricted permissions if possible) and set it as OPENAI_API_KEY on your server only. Redeploy.
4–7 minCheck usageOpen Usage and filter by project and key for requests you didn't make. Set a project spend limit.
7–10 minClose the holeRemove the key from the frontend bundle, .env commits and git history. Move all OpenAI calls behind your backend.

Stop the next leak

  • Keep the key in a server-side env var. Never use a VITE_, NEXT_PUBLIC_ or EXPO_PUBLIC_ variable or hard-code it in frontend code.
  • Call the provider from your backend or an edge function, and add .env* to .gitignore.
  • Re-scan the live site after every deploy. Keys also leak through JS bundles, source maps and exposed .env or .git paths.

Check your live app

A free, read-only public-surface scan. It cannot diagnose private sessions or every cause described above.

Read-only. No writes or row contents.

FAQ

Will OpenAI catch the leak for me?

Sometimes. OpenAI disables keys it detects as leaked and emails you, but don't wait for that.

Can I get charges refunded?

Contact support through help.openai.com with the timeline. Fast revocation and spend limits are what actually cap the loss.

Is a key in a VITE_ or NEXT_PUBLIC_ variable leaked?

Yes. Those values are in public JavaScript on your live site.

Sources

Related

Read as Markdown · Scan methodology