How to avoid pasting API keys into AI chats
An API key is a password for software. If one ends up in a chat window, treat it as exposed and replace it. This guide explains what keys look like, how they end up in pastes, the habits that prevent it, and what to do when one slips through.
What an API key looks like
Most providers issue keys as one long string of letters and digits. Many start with a short, recognisable prefix so the provider (and secret scanners) can tell what the string is. A cloud access key might start with four capital letters and continue with sixteen more characters. A source-hosting token might start with a short word and an underscore. A payment key often says whether it is a test key or a live key right in the prefix.
Some secrets have no prefix at all. A cloud secret access key, a database password or a signing secret is often just a random-looking string. These usually appear next to a label such as secret, token, password or api_key, followed by a colon or an equals sign. That label is often the only clue.
Two other things carry secrets and are easy to miss: connection strings that contain a password (user:password@host), and private key blocks that begin with a line of dashes and the words PRIVATE KEY.
Why keys end up in AI chats
Nobody pastes a key on purpose. It happens because the useful thing to paste is something else, and the key rides along:
- Error logs and stack traces. A request dump or a failing command often prints headers, including an authorization header.
- Config files. Asking "why does this fail?" with a whole
.env, YAML or JSON file pasted in. - Shell history and curl commands. A command copied from a terminal with a token in it.
- Code with a hard-coded key. Fine on a laptop, risky the moment it is copied elsewhere.
- Screenshots of terminals or dashboards, which no text tool can read for you.
Habits that prevent most leaks
- Keep secrets out of code. Load them from environment variables or a secrets manager, so a pasted file does not contain them.
- Trim before you paste. Paste the failing function and the error line, not the whole file or the whole log.
- Replace values by hand when in doubt. Swap the real value for
YOUR_API_KEYyourself. The model rarely needs the real one. - Use narrow keys. A key limited to one project, one action and a short life does less damage when it leaks.
- Use separate test keys for experiments, so a test key in a chat is a small problem.
- Do not rely on memory. Add a check at the point of pasting, which is where mistakes happen.
If a key was pasted
Assume it is compromised, even if the chat is private. The steps are the same for nearly every provider:
- Revoke or rotate the key in the provider's dashboard. Rotation matters more than deleting the chat.
- Create a replacement and update the places that use it.
- Check the usage log for the key, if the provider offers one, for calls you do not recognise.
- Check where else it was copied: commits, tickets, shared documents, other chats.
- If the key was in a commit, rotating it is still required. Rewriting history does not undo copies.
Do this first and delete the conversation second.
Where Paste Guard helps
Paste Guard is a Chrome extension that looks at text at the moment you paste it into a supported AI chat site. If it finds something that looks like a key, token, private key block or password in a connection string, it pauses the paste and offers three choices: paste a masked version (the key becomes a tag such as [API_KEY_1]), paste anyway, or cancel. The check happens on your device and nothing is sent anywhere, which you can verify in the browser's Network tab.
It recognises the prefixes used by many common providers, labelled secrets such as secret: ..., private key blocks and connection strings with passwords. You can see the full list on the What it detects page.
Where it cannot help
- Unlabelled random strings. A secret with no known prefix and no label looks like any other random text, so it can be missed.
- New or unusual formats. It matches patterns it knows. A provider's brand-new format may not be known yet.
- Screenshots and images. It reads text, not pictures.
- Typing, drag and drop, and unsupported sites. It watches pastes on the listed sites only.
- Keys already pasted. It cannot take anything back.
If it misses a format, you can email rkhajuira12345@gmail.com using made-up samples only. Never send a real secret.