Replit API key exposed: secrets leaking from a public Repl
Symptoms
- A surprise bill from OpenAI or another API provider on a key you used in a Repl
- An email from the provider saying your key was leaked or found publicly exposed
- The key sits in plain text in a public Repl's source, an old fork, or version history
- The key is embedded in frontend JavaScript, delivered to every visitor's browser
Why it happens
Repls are public by default
Anyone can read a public Repl's source, and automated scrapers specifically harvest Replit for hardcoded credentials. A key in code is a key on a billboard.
Key values pasted into Agent prompts
If you paste a real key value into a prompt, the Agent generates code with that key hardcoded, and now it lives in your source.
Agent-written frontend calls third-party APIs directly
The Agent often writes browser code that calls APIs like OpenAI straight from the frontend, which ships the key to every visitor's browser where DevTools makes it trivially readable.
History and forks retain old values
Moving a key to the Secrets manager later does not scrub version history or forks. Anyone who forked or scraped the Repl earlier still has the original value.
How to fix it
- Rotate the compromised key immediatelyTreat any key that was ever hardcoded in a Repl as stolen; automated scrapers specifically harvest Replit for credentials. Go to the issuing provider's dashboard, revoke the key, and issue a new one. Removing the key from your current code is not enough, because version history and existing forks still contain the old value and may already have been copied.
- Move every credential into Replit's Secrets paneAdd each key by name in the Secrets pane and reference it in code as process.env.KEY_NAME in Node or os.environ['KEY_NAME'] in Python. The value stays out of your source entirely.
- Keep real key values out of Agent promptsIf you paste a key value into a prompt, the Agent generates code with it hardcoded. Give it the environment variable name instead. A prompt like 'Use the OPENAI_API_KEY environment variable from Secrets via process.env; never hardcode any key values' gets you code that reads the secret correctly.
- Make the Repl privateIf the Repl contains anything sensitive, change its visibility in Settings so the source is no longer readable by anyone with the URL. This does not undo past exposure, which is why rotation comes first.
- Move third-party API calls behind your own serverCheck Agent-generated frontend code for direct calls to third-party APIs with embedded keys. Route those calls through a server endpoint you control, so the browser talks to your server and only your server holds the key.
- Audit the codebase and set a financial backstopSearch your code and shell history for leftover hardcoded values before publishing anything. On the provider side, set spend limits and usage alerts so a future leak cannot run up an unbounded bill.
How to prevent it
- Store every credential in the Secrets pane from the first prompt; never type a real key value into chat or code.
- Keep Repls private by default when they involve credentials, customer data, or billing.
- Route all third-party API calls through your own backend; the browser should never hold a key.
- Set spend limits and alerts with every API provider you use.
- Before making a Repl public or publishing, audit code and shell history for hardcoded values.
Tools that actually fix this
Recommended because they address the failure mode above, not because of the payout. Some are affiliate links; see how we choose.
A purpose-built secret scanner covering 450+ key types. Its ggshield pre-commit hook blocks a key from ever being pushed, and history scanning finds the ones you already leaked. Free for individuals.
Try GitGuardian →All-in-one appsec (code scanning, dependencies, secret detection, containers) with low-noise output, built for small teams that cannot run five separate tools. One dashboard covers several failure modes.
Try Aikido Security →Frequently asked questions
Is removing a hardcoded API key from my Repl enough to fix the leak?
No. Removing a hardcoded API key from your current Replit code does not fix the leak, because the old value survives in version history and in any forks other users have already made. Automated scrapers harvest public Repls continuously, so assume the key was copied. The only real fix is rotating the key at the provider and storing the replacement in Replit Secrets.
How did my OpenAI key leak from Replit?
Repls are public by default, so a hardcoded OpenAI key in your source was readable by anyone, and scrapers specifically target Replit for exposed credentials. The Replit Agent can also embed a key in frontend JavaScript if it writes browser code that calls the OpenAI API directly, which sends the key to every visitor. Either path ends in a surprise bill or a leaked-key warning.
Where should API keys live in a Replit project?
API keys in a Replit project belong in the Secrets pane, referenced in code as process.env.KEY_NAME in Node or os.environ['KEY_NAME'] in Python. Never paste a real key value into an Agent prompt; give the Agent the environment variable name instead. Third-party API calls should run from your server code, not from the browser.
Can the Replit Agent leak a key on its own?
Yes, in two ways. If you paste a key value into an Agent prompt, the Agent generates code with the key hardcoded, and it often writes frontend code that calls third-party APIs directly, shipping the key to every visitor's browser. Give the Agent environment variable names only, and review generated frontend code for direct API calls before publishing.
Sources
- Vibe App Scanner: Replit Exposed API Keys
- Vibe App Scanner: Replit Security
- Replit Blog: 16 Ways to Vibe Code Securely
- Replit Docs: Vibe Code Security Checklist
Related errors
The AI put your API key in the frontend: OpenAI, Stripe, or Supabase keys visible in the JS bundle
Lovable API key exposed: secrets visible in your client-side code
Accidentally committed an API key to GitHub
Why is my OpenAI API bill so high? No rate limiting on your AI endpoints
The Vibe Oops briefing
One email when something ships to production that should not have. New incidents, new error guides, no filler.