Revoke the exposed OpenAI API key
An OpenAI API key (sk-proj-..., or an older sk-... key) is meant for a server. In a browser bundle anyone who loads the page can copy it and run requests billed to the account, or read files and assistants the project stored. Calling OpenAI from the browser always needs a key there, which is why the fix is a server-side endpoint, not a better hiding place.
Find out whether your site has this problem, and every other check, in one free scan.
Check your site freeWhy it matters
An OpenAI API key lets whoever copies it run requests billed to the business's account, and read what the project stored there (files, assistants, fine-tunes). Keys found in public pages are collected and used within hours.
How to fix
- 1 Revoke the key in the OpenAI dashboard (API keys) and create a new one. Revoking is the only step that stops the copied key from working.
- 2 Move every call to OpenAI behind an endpoint on your own server that holds the new key in an environment variable, checks who is asking and limits how often.
- 3 Purge the old key from git history so it is not recoverable from a prior commit.
- 4 Redeploy, confirm the shipped bundle has no sk- key in it, and check the usage page for spend you did not make.
Common mistakes
- Putting the key in a build-time environment variable and assuming that keeps it private: a bundler that inlines it (NEXT_PUBLIC_, VITE_, PUBLIC_) ships it to every visitor.
- Removing the key from the current build without revoking it: copies in git history, old deploys and CDN caches keep working until it is revoked.
- Replacing the key with a new one in the same browser code, so the new key ships just like the old one.
How to verify
- 1 Re-run the scan and confirm the OpenAI API key finding is gone.
- 2 Search the deployed JavaScript for sk-proj- and T3BlbkFJ to confirm no key remains, not just the source files.
- 3 Check the OpenAI usage page for requests you did not make, and confirm the old key is listed as revoked.
Related checks
Ready to see where you stand?
Scan your site and get your Engineering Score with a prioritized roadmap in under a minute, no signup required.
