# 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

| When | Do | How |
|---|---|---|
| 0–2 min | Revoke | Open platform.openai.com/api-keys and delete the leaked key. |
| 2–4 min | Replace | Create a new key (restricted permissions if possible) and set it as `OPENAI_API_KEY` on your server only. Redeploy. |
| 4–7 min | Check usage | Open Usage and filter by project and key for requests you didn't make. Set a project spend limit. |
| 7–10 min | Close the hole | Remove 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.

> **Scan box (use the site's ScanBox component):** Check whether your live app has this problem. Paste your URL for a free outside-in scan covering exposed keys, open database rules, CORS and security headers. [Scan my app free →](https://proofforge.live/#scan)

## 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

- [OpenAI: Best practices for API key safety](https://help.openai.com/en/articles/5112595-best-practices-for-api-key-safety)
- [OpenAI: API keys page](https://platform.openai.com/api-keys)

## Related

- [Fix: OpenAI key exposed](/fix/openai-key-exposed)
- [OpenAI 'your API key was leaked and disabled': what to do](/errors/openai-key-disabled-leaked)
- [Fix OpenAI 429 'You exceeded your current quota'](/errors/openai-insufficient-quota)
- [Fix OpenAI 401 'Incorrect API key provided'](/errors/openai-incorrect-api-key)
- [Exposed API key checker](/tools/exposed-api-key-checker)
- [Fix: source maps exposed](/fix/source-maps-exposed)
- [All leaked-key guides](/leaked-keys)
