You pasted an API key into an AI chat. What to do now
In short
- Treat a pasted key as compromised, even if you deleted the chat.
- Rotate first, then check usage and clean up.
- Make it hard to repeat: scrub before pasting.
In this guide
It happens to careful people. You paste a config file or a log to ask a quick question, and halfway through the answer you notice a live key sitting in the prompt. Here is what to do, in order. Do not skip to the end.
1. Treat the key as compromised
You cannot verify who or what has seen the text now. The provider stores conversations for a period, may review them, and could be breached. "Probably fine" is not a security posture. A key that has been pasted anywhere outside your own systems gets rotated. Deleting the conversation is worth doing afterwards, but it does not undo the exposure and some providers keep deleted chats for a while.
2. Rotate it, the safe way
Create the new credential first, deploy it, then revoke the old one. That order avoids an outage. Where the knobs are for common providers:
- AWS access keys. IAM console, the user, Security credentials. Create a second access key, update every place that uses it, mark the old key inactive, confirm nothing broke, then delete it. If the key belonged to the root user, also enable MFA and stop using root keys altogether.
- GitHub personal access tokens. Settings, Developer settings, Personal access tokens. Generate a new one with the minimum scopes, replace it, delete the old one. GitHub also runs secret scanning on public repositories and will often revoke well known token formats automatically.
- Stripe. Developers, API keys. Use "Roll key" on the exposed secret key; you can set a grace period of a few hours so the old key keeps working while you deploy.
- OpenAI, Anthropic and similar AI platforms. The API keys page of the platform dashboard. Create a new key, update your apps, revoke the old one. Check the usage page for spend you do not recognise.
- Slack. For bot and user tokens, regenerate them in the app's OAuth settings, or reinstall the app to the workspace, which issues fresh tokens.
- Google Cloud. API keys: APIs and Services, Credentials, regenerate. Service account keys: create a new key, deploy, delete the old key ID.
- Database passwords and SMTP credentials. Change the password on the server, update the application, restart what needs restarting.
If the key was a long lived one that you cannot easily rotate because it is baked into customer installations, that is a design problem worth fixing this week, not a reason to leave the key alive.
3. Look for misuse
Check the provider's audit or usage logs for activity after the moment you pasted the key. Unknown IP addresses, unusual regions, new resources, spikes in spend. Cloud providers in particular have alerting for this; turn it on if it was off. If you find anything, your incident response process starts now, and for personal data of EU residents the 72 hour breach notification clock may be running.
4. Clean up the chat
Delete the conversation, and if the product offers it, request deletion of your data for that period. Switch off model training in the account settings if you had not already. This is housekeeping, not a fix.
5. Make it hard to repeat
- Keep secrets out of files you are likely to paste. Use environment variables or a secret manager, and keep
.envfiles out of version control. - Prefer short lived tokens and least privilege scopes, so a leak hurts less.
- Install a scrubber that runs before text reaches the clipboard. Scrub for AI recognises the common key formats (AWS, GitHub, Stripe, Slack, Google, OpenAI, Anthropic, JWTs, Bearer tokens, passwords in URLs and in
key=valuelines) and replaces them with placeholders locally. - Add a pre-commit secret scanner such as gitleaks to repositories, so keys do not end up in files in the first place.
A note on blame
Pasting a key into a chat is a predictable result of putting secrets in plain text next to the things people need to copy. Fix the system, rotate the key, move on.
Scrub before you paste
Scrub for AI replaces emails, phone numbers, IBANs, API keys and passwords with placeholders in one click, and puts them back when the answer returns. Free, runs offline, no account.
More: all guides · Scrub for AI · Copy for AI · Tables for AI