vibe-audit.lab

guides · 2026-11-14

What to Do in the First Hour After an OpenAI API Key Leaks From Your App

Published 2026-11-14 · Reviewed 2026-11-14 · By the Ingenious AI team

The short answer

Revoke the key first and ask questions later: a leaked OpenAI key is a blank cheque against your account, and automated abuse usually starts within hours. Then issue a replacement into a server-side environment variable only, set project spend limits and alerts, and find the path it escaped through — client bundle, public commit or shared screenshot — because a new key in the same hole leaks again.

Check your own app free: paste your code or enter your site URL on the Vibe-Code Audit homepage — the free scan checks for exposed secrets, injection flaws, XSS patterns, missing headers and exposed .env/.git paths, with a copy-paste fix for every finding. No credit card.

Minute 0–10: revoke, do not investigate first

Every other incident type rewards diagnosis before action. Key leaks invert that: the meter is running. Someone testing a found key does not browse politely — scripts fire model calls to confirm the key works and then resell or drain it, and a single evening of high-throughput calls can reach hundreds of dollars. Open the OpenAI dashboard, revoke the exposed key, and only then start the archaeology. Vibe-Code Audit's scanner detects both the classic sk- shape and the sk-proj- project-key shape in pasted code; if a scan of your own code finds one in client-side context, treat this playbook as already started.

While you are in the dashboard, read the usage graph. Spikes from models you never call, or traffic while your app was idle, confirm abuse — useful for the support ticket and for calibrating how much of your history to audit.

Minute 10–30: replace it where it cannot leak

The replacement key goes exactly one place: a server-side environment variable or secret manager, read by code that runs on your infrastructure. The architectural rule that prevents most AI-app leaks is simple — the browser never talks to OpenAI directly. Your frontend calls your own API route; the route (which holds the key) calls OpenAI. AI generators violate this constantly because calling the API straight from the component is fewer lines, and 'fewer lines' is what the demo rewards.

If the leaked key was committed to git, remember the history rule: deleting the line does not unpublish it. The repo needs the same treatment as the .git exposure case — assume permanence, rotate, and scrub history only as tidiness, never as the security fix.

What is Leaked API key?

a credential that has appeared anywhere an unintended person could read it — a browser bundle, a public repository, a log file, a chat transcript. For billing-bearing keys like OpenAI's, 'leaked' means 'already being tested by strangers'; providers and attackers both scan for the sk- key shape automatically.

Minute 30–60: cap the blast radius forever

Set a project-level monthly budget and usage alerts in the dashboard before you ship the replacement. A hard limit converts the next leak from an unbounded bill into an outage you notice. Use a separate key per environment and per app, so revocation is surgical and usage graphs tell you which system is calling. If your plan supports it, restrict the key's model permissions to the ones your app actually uses.

Then close the specific hole. Bundle leak? The key moves server-side and you add a build-time check that fails if 'sk-' appears in client output. Repo leak? Pre-commit secret scanning joins the workflow. Screenshot or chat leak? The key was pasted somewhere it should never be typed — change the habit, and never paste live keys into any AI chat, including to debug them.

What to tell support, and what to watch next

If usage shows abuse, file the provider ticket the same day with the revocation timestamp and the anomalous window; providers sometimes credit clearly-fraudulent usage, and the request is strongest when your timeline is documented. For the following two weeks, glance at the usage graph daily. A second spike after rotation means a second copy of the old key is still live somewhere — usually a forgotten staging deploy or a mobile build — and the hunt resumes with the new evidence.

Worked example: BrightPanel, an AI invoice tool

BrightPanel (fictional), a 40-customer invoicing SaaS, shipped a settings page whose 'AI summary' feature called OpenAI directly from the browser with an sk-proj- key. A user's bug report screenshot — posted publicly — showed the key in the network tab. The founder revoked it 26 minutes after the report; the usage graph already showed $61 of foreign calls to a model the app never used. The feature was rebuilt behind an API route in one afternoon, a $150 monthly project cap and 80% alert were set, and the replacement key lived only in the host's environment settings. Final bill for the incident: the $61, credited in part after a documented support ticket.

Five actions to take today

  1. Revoke the exposed key in the provider dashboard immediately — before investigating how it leaked.
  2. Read the usage graph for the exposure window: unfamiliar models, hours or volumes mean confirmed abuse; save the timeline.
  3. Issue a fresh key into a server-side environment variable only, and route all model calls through your own backend — never the browser.
  4. Set a monthly spend cap and usage alerts on the project, and use a separate key per app and environment.
  5. Find and close the leak path (bundle, repo history, logs, screenshots), then re-scan the shipped code to prove no key shape remains client-side.

Sources

Frequently asked questions

How fast are leaked keys actually abused?

Fast enough that 'I'll rotate tomorrow' is an expensive plan. Key shapes are public knowledge, scanners watch public commits and bundles continuously, and the first test calls are automated. Assume hours, not weeks.

Can I just delete the key from my code and push?

No. If it was in a bundle, copies are cached and archived; if it was in git, it is in history. Deletion stops nothing — revocation is the only move that devalues a leaked key.

Should the frontend ever call the OpenAI API directly?

Not with your key. Browser-direct calls require the key to ship to the browser. Proxy through a small backend route you control; it also gives you rate limiting and per-user accounting for free.

Will rotating break my production app?

Only until the new key is in the environment and the service restarts — sequence it: create new key, deploy it, verify, then revoke the old one if you need zero downtime. For a confirmed leak, accept the brief outage instead.

What spend limit should I set?

Roughly 1.5× your highest legitimate month. The cap is a tripwire, not a budget: tight enough to hurt a thief quickly, loose enough that a good month does not take you offline.

Related guides

Browse the full library on the guides index, run the checks in the launch audit, or compare plans on pricing.


Informational explainer, not a security guarantee. Scan your code free before every deploy.

← all guides

← Back