SIGNAL GRID ACADEMY
All courses

Bots & agents · Intermediate

Safe & Affordable Bots: Approvals, Security, Costs

Keep your keys safe, your bots honest and your AI bill small.

4 lessons 54 min Certificate
Steps for
Join free to track progress

Lesson 1 · 14 min · Windows

Secrets: store, hide, rotate

Leaked API keys get abused within minutes. Three rules:

  1. Never in code or chats. Use environment variables or a .env file listed in .gitignore.
  2. One key per bot. If one leaks, you revoke one, not everything.
  3. Rotate keys every few months and immediately if you suspect a leak.

Using a .env file

text
# .env  (add ".env" to .gitignore!)
ANTHROPIC_API_KEY=sk-ant-...
TELEGRAM_TOKEN=123:abc...

Python: pip install python-dotenv then from dotenv import load_dotenv; load_dotenv().

Check you didn't commit a secret

Windows steps
powershell
git grep -n "sk-ant-"
Select-String -Path .\* -Pattern "sk-ant-" -List

If a key was ever pushed to GitHub, revoke it in the provider's console now. Deleting the file isn't enough: it stays in history.

Hosted secrets

On Cloudflare Workers use npx wrangler secret put ANTHROPIC_API_KEY; on n8n use Credentials. Secrets set this way never appear in your code.

Quick quiz

Pass 2 of 3
1. A key was pushed to a public repo yesterday. What's the first step?
2. Why one key per bot?
3. Where should .env be listed?
Join free to take the quiz

Quick assignment

To do

Move one bot's key into an environment variable or .env (with .gitignore). Paste your .gitignore and the line of code that reads the key.

Hint: Never paste the key itself.

Join free to submit

Stuck or proud of what you built? Discuss this course in the forum.