GUIDE · API KEYS
How to hide API keys before sharing code with AI
Keys hide in more places than config files: hard-coded in a script, inside a curl command, in a stack trace. Here is where to look and what to replace them with.
Where API keys usually hide
- Hard-coded strings in scripts and notebooks, such as
api_key = "sk-...". - curl and HTTP examples with an
Authorization: Bearer ...orBasic ...header. - URLs with tokens in the query string, such as
?api_key=...or?token=.... - Logs and stack traces that print request headers or full connection strings.
- Webhook URLs, for example Slack incoming webhooks: anyone with the URL can post to your channel.
How to recognise a key by its shape
Many providers use recognisable prefixes, which makes them easy to find:
sk-,sk_live_,rk_live_: secret keys used by many AI and payment providersAKIAorASIAfollowed by 16 characters: AWS access key IDsAIza: Google API keysghp_,github_pat_: GitHub tokensxoxb-,xoxp-: Slack tokenseyJ...with two dots: JSON Web Tokens, often a live session
Hushpaste publishes the exact patterns it uses in a free JSON rule file, if you want to build your own check.
What to replace them with
Use a placeholder that keeps the meaning, not just XXXX. [API_KEY_1] tells the model it is a key; XXXX may make it think the value is broken and send it chasing the wrong bug.
curl https://api.example.com/v1/charges \
-H "Authorization: Bearer [BEARER_TOKEN_1]"
Keep the habit cheap
People skip masking when it is slow. The fastest routine is: paste into a local masking tool, copy the masked text, ask the AI, paste the answer back to restore values. It takes seconds and nothing leaves your machine.
Mask it in one paste. The free Hushpaste tool finds keys, tokens, emails, IBANs and other secrets in your text and swaps them for placeholders, right in your browser. Nothing is uploaded. When the AI answers, paste the reply back and the real values return.
Open the free tool