Skip to content
ShipSafeStack

Checklist

Leaked OpenAI API key? What to do right now

Short answer. Treat the key as copied. Delete it in the OpenAI API keys settings, create a replacement with the narrowest permission the app needs, put that value in the host's environment, and redeploy. Then read the Usage page. Rewriting git history does not retire a key that already left the repo.

Updated 30 Nov 2026

This is a practical checklist, not a guarantee. It is not a penetration test, a compliance audit, or proof that an app is safe to launch.

An OpenAI API key is a credential for your API account. OpenAI's account security guide says an exposed key can allow API usage through your account, which can result in charges or activity that violates their terms. Deleting the line from a file does not delete the key. This page is the first sitting after a leak. It is a checklist, not a statement that the account is fine.

The same shape for a GitHub token is Leaked a GitHub token?. An Anthropic key is Leaked Anthropic key?. An AWS access key is Leaked AWS access key?. A Gemini key is Leaked Gemini API key?. A Supabase secret key is Service role key leaked? What to do.

Signs the key is out

You do not need all of these. Any one is a reason to rotate.

  • The Usage page shows requests or spend you do not recognize. OpenAI's key safety guide says a compromised key can use your quota without your consent, and that usage is tracked on the Usage page.
  • The key is in a public repository, a commit, a chat log, or a client bundle. A name the framework inlines for the browser is public. On Next.js that prefix is NEXT_PUBLIC_. On Vite it is VITE_. The wider pass is API keys in the frontend.
  • GitHub blocked a push, or a secret scanning alert names an OpenAI key. GitHub's supported patterns list OpenAI API keys for partner notification, user alerts, push protection, and a validity check.
  • OpenAI already turned the key off. The account security guide says that when OpenAI detects an API key on the public internet, or leaked inside an app in an app store, the key is disabled immediately. A disabled key still needs a replacement, and you still remove the old value from the repo and the host.

Delete the key, then create a narrower one

Do this before you clean git. GitHub's leaked-secret tutorial says that removing a secret from the latest commit, or deleting the repository, does not by itself stop a value that was already copied. OpenAI's account security guide says to delete the affected key through the API key dashboard, then review usage.

1. Open the API keys page for the key's scope. Organization keys are at platform.openai.com/settings/organization/api-keys. Project keys are under organization settings, then the project, then API Keys. OpenAI's project guide says a personal key created in a project is scoped to that project. If you cannot see the key, ask an organization or project owner to delete it. OpenAI's key lookup article says you can call https://api.openai.com/v1/me with the key as a bearer token to see which organization it belongs to. Do that only from a machine you control, and do not paste the key into a chat. 2. Delete the leaked key. If you are not sure which one it is, delete every key you cannot account for, then issue replacements for the apps that must keep running. 3. Create the replacement from the same project's API Keys page, with + Create new secret key. OpenAI shows the secret once. Save it in the host's secret store, not in the repository. The project guide says user-owned keys can be All (the default, full permissions), Restricted (scopes you pick, such as none, read, or write on a resource), or Read only. A leaked key that could call every endpoint should not be replaced with another All key if Restricted covers the calls the app makes. Service account keys are different: the project guide says they can read and write all API resources in the project by default, and you change those permissions afterward in API Keys settings. 4. Set an expiration if the dialog offers one. The key safety guide says project keys can expire, after which requests from that key are rejected, and that administrators can set a maximum lifetime at the organization or project level. Project limits cannot exceed the organization limit.

A planned rotation, where the old key is not yet public, can keep the old key alive until the new deployment works. Vercel's rotating secrets guide says to put the new value on the host and redeploy before you invalidate the old credential, so production does not break. A key that is already in a public repo, a bundle, or a chat is not that case. OpenAI tells you to delete it.

Put the new key on the host

The new value belongs in the environment of the server that calls OpenAI, under a name the browser bundle does not inline. OpenAI's key safety guide says to use OPENAI_API_KEY and never to deploy the key in a browser or a mobile app.

On Vercel, open the project, then Environment Variables, edit OPENAI_API_KEY, and save it for Production and Preview if both call the API. Vercel's environment variables page says a change applies only to new deployments. The running deployment keeps the value it was built with. Redeploy after you save. Vercel's managing-deployments page lists a change to environment variables as a reason to redeploy. Other hosts work the same way: the new value is unused until the next build or function deploy that reads it.

Then search the repo for the old key and for NEXT_PUBLIC_OPENAI and VITE_OPENAI. Remove those. A commit that deletes the line is the cleanup. It is not the revoke.

Read usage, then set a limit

Open the Usage page and compare the recent days with the work you expected. OpenAI's project guide says usage can be broken down by project, and that seeing a project's Usage Dashboard depends on your organization role and the dashboard's visibility setting. Being a project owner does not by itself grant that view. If the page is missing, check the dashboard, or ask an organization owner. If the spend is unexplained after you delete the key, OpenAI's account security guide says to contact Support from the Help Center and to include activity you did not authorize. Leave the key itself out of that message.

Spend controls are separate from deleting the key. The project guide says monthly spend limits exist at the organization and the project. A limit can watch spending without stopping requests. Enforce a hard limit makes later API requests fail after tracked spend reaches the amount. Enforcement is not instantaneous, so recorded spend can still go slightly past the number. Spend alerts notify you. They do not stop traffic. Creating a project spend limit also creates an alert at 100 percent by default. Organization and project owners receive those alerts, and you can add other recipients.

The path OpenAI documents: organization settings, then the project, then Limits. Set the monthly spend limit and the alert threshold, and turn on Enforce a hard limit if you want traffic to stop. You can also limit which models the project may call on that page. If a control is not where this paragraph says, use the controls on the Limits page you actually see. OpenAI's spend-limit troubleshooting page is the current description of the error codes those limits return.

The key safety guide also documents IP allowlisting: when it is on, requests from other addresses are rejected even if they carry a valid key. That is a network control for a backend you can name by address. It is not a substitute for deleting the leaked key. Check the help center article linked from that guide before you turn it on.

Git history does not un-leak it

Rewriting history, force-pushing, or deleting the repository removes the key from the copy GitHub shows after the rewrite. It does not remove copies already cloned, cached, or scanned. GitHub's leaked-secret tutorial says to treat a leaked secret as compromised, and that removing it from the codebase, pushing a new commit, or deleting and recreating the repository does not prevent exploitation. GitHub's secret scanning page says that removing a secret from git history is time-intensive and often unnecessary once the credential is revoked.

Rotate first. Rewrite history only if you still want the value gone from the repository's current history, and expect that to be a separate, careful git operation. Do not put the old key in the commit message that removes it.

Keep the next key off the client

OpenAI's key safety guide says requests should go through your own backend, where the key can stay. A route or edge function that checks who is calling, then calls OpenAI, is that shape. The browser receives the model's answer, not the key.

  • Do not put the key in client code, a NEXT_PUBLIC_ or VITE_ variable, a chat, or a screenshot. Sharing keys is against OpenAI's terms. The key safety guide says to invite teammates instead of handing them your key.
  • Add a limit on the route that spends the key. OpenAI's project rate limits cap the API account. They do not cap one visitor of your app. The notes are in rate limiting.
  • On GitHub, push protection for your user is on by default and blocks supported secrets, including partner patterns, on pushes to public repositories. GitHub's security features page says secret scanning runs on public repositories, and that secret scanning alerts for users and repository push protection are available for public repositories by default. Organization-owned private repositories need GitHub Secret Protection. Enabling repository push protection is under Settings, Advanced Security, Secret Protection, then Push protection. Someone with write access can bypass a repository block. A bypass is not a reason to leave the key in the commit.
  • Use a different key per app or project, with an expiration, so the next leak is one key and not the whole account. OpenAI's key safety guide also describes workload identity federation for supported workloads, which exchanges a provider identity for a short-lived token instead of storing a long-lived key.

After the new deployment, if the route starts failing, that is often the old value still on a previous deployment, or the new key's permissions excluding the endpoint you call. Error reports from the running app are a separate tool. Sentry is the directory entry, and the setup notes are Add Sentry to a vibe-coded app. Sentry does not revoke the key.

Then run a free passive check on the public URL. It can see a key that shipped in a public script. It does not read your OpenAI account or a private repository. The worksheets for the rest of the pass are the checklist pack and the pre-launch checklist. How generated code keeps picking up secrets is how to keep API keys out of AI-generated code.

Lovable, Bolt, and Cursor

These builders do not change what the key is. They change where people paste it.

  • Lovable. An OpenAI key belongs in Secrets. Lovable's secrets docs say Secrets are injected into Edge Functions and are not part of the browser bundle. A VITE_ name is a public build value and belongs in .env, which Lovable says to keep committed. The project pass is how to secure a Lovable app.
  • Bolt. Server functions read Secrets. Bolt's secrets docs say the value is not written into project files, browser code, or the published site. A value the browser reads from .env is sent to visitors. The project pass is how to secure a Bolt.new app.
  • Cursor. The editor does not host the app. The key stays in the host environment, not in a file the agent commits and not in the chat. The settings pass is how to secure a Cursor-built app.

If the call runs in a Supabase Edge Function, the key is a secret of that function, read on the server. It is not a VITE_ or NEXT_PUBLIC_ value, and it is not the Supabase service role key. Those are different credentials.

FAQ

I deleted the key from the repo. Is the OpenAI key dead?

No. OpenAI's account security guide says to delete the key in the API key dashboard. A copy in git history, a fork, a chat, or the host's current deployment keeps working until that key is deleted or OpenAI has disabled it. Removing the line is the cleanup after the delete.

Will OpenAI disable a key it finds on the public internet?

The account security guide says that when OpenAI detects an API key on the public internet, or leaked inside an app in an app store, the key is disabled immediately. Do not wait for that. Delete it yourself, issue a replacement, and read the Usage page. A key in a private repo or a private chat may not be something OpenAI has seen.

Can I put the key in NEXT_PUBLIC_OPENAI_API_KEY or VITE_OPENAI_API_KEY?

No. Those prefixes are inlined into the browser bundle. OpenAI's key safety guide says not to deploy the key in a browser or a mobile app, because someone else can copy it and call the API as you. Call OpenAI from a server route or an edge function, and keep OPENAI_API_KEY in that server's environment.

Does a spend alert stop a leaked key from running up a bill?

No. OpenAI's project guide says spend alerts notify you and do not stop requests. A monthly limit without Enforce a hard limit also monitors spending while requests continue. With the hard limit on, later requests fail after tracked spend reaches the amount, and recorded spend can still go slightly past it because enforcement is not instantaneous. The hard limit is a backstop. Deleting the key is what stops that key.

Sources

Checked 21 Nov 2026.

Informational only. This page describes checks and vendor documentation. It is not a security audit, a penetration test, or a certification, and it is not a guarantee.

Newsletter

A short weekly note on new tools and security checklists. No spam, unsubscribe anytime.