Dev.to WebDev 🛠 Dev 👁 0 📖 1 min read

OpenAI "your API key was leaked" and disabled: what to do, in order

You get an email, or your calls start failing with: "We have determined that your OpenAI API key was leaked." Here is what happened and what to do, in order. What it means OpenAI found your key somewhere public, usually

You get an email, or your calls start failing with: "We have determined that your OpenAI API key was leaked." Here is what happened and what to do, in order.

What it means
OpenAI found your key somewhere public, usually a GitHub repo or a website's JavaScript bundle, and disabled it. That key will not work again.

What to do, in order

  1. Create a new key. Do not try to revive the old one.
  2. Keep it server-side. The key must live in a server environment variable and be called from a server route or edge function. It must not be in NEXT_PUBLIC_, VITE_ or any variable that reaches the browser.
  3. Check Usage and billing for spend you did not make. Set a monthly usage limit on the new key.
  4. Remove the old key from the code and from git history. Deleting the line in a new commit is not enough. The old commit still has it. Rotating makes the old value useless, but a clean history stops the next key from leaking the same way.
  5. Search your live site. Open your deployed JavaScript and look for strings starting with sk-. If it is there, the build is still shipping it. Redeploy after the fix and check again from a private window.

How keys end up in the browser

  • A frontend call made straight to the OpenAI API.
  • A secret put in a VITE_ or NEXT_PUBLIC_ variable, which the bundler inlines into public code.
  • A .env file committed to a public repo, or served by the host.

Prevent the repeat
Put a thin server route between your app and OpenAI. Require login or rate limits on that route so strangers cannot spend your budget through it.

Full steps for this error: https://proofforge.live/errors/openai-key-disabled-leaked . To check whether your live app ships any secret keys today, the free outside check is at https://proofforge.live

📰 Read the original article on Dev.to WebDev

Originally published by Dev.to WebDev. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.