Don't Send API Keys to Your AI Agent in Telegram — Set Up Simple GPG Instead

blog_gpg.avif

The problem

You're building an AI agent. It runs your crypto research, posts to social media, schedules reports. Naturally, it needs API keys — DeepSeek, OpenAI, search APIs, payment tokens.

And what's the easiest way to give it those keys?

Paste them into the Telegram chat.

I did it myself: SERPER_API_KEY=sk-abc123def456... — right into the DM. It felt normal. It wasn't.

Why Telegram is the wrong channel for secrets

  1. Telegram messages are plaintext on their servers. The key sits in a chat database, visible to anyone with access — Telegram's systems, a compromised account, a synced device.

  2. Chat history is forever. Even if you delete the message, backups, sync logs, and session records may retain it.

  3. You're training your agent's memory with secrets. The conversation context gets cached, compressed, stored in state.db — and if that database leaks, the keys leak with it.

  4. Your agent isn't a vault. It's a tool that writes logs, runs cron jobs, and stores conversation history. Secrets in the chat become secrets in the logs.

The fix: GPG email — simple, open, asymmetric

The clean solution takes 10 minutes and works with tools you already have (Gpg4win on Windows, gpg on the server).

1. Generate a key pair (Windows, Kleopatra)

File → New Key Pair → Name + email → Generate

You get two keys:

  • Public key — safe to share, used to ENCRYPT
  • Private key — stays on your machine, used to DECRYPT

2. Give the server the public key

# On the server, import the public key from a keyserver
gpg --keyserver keyserver.ubuntu.com --recv-keys <KEY_ID>

The server can now encrypt anything for you — but cannot decrypt it. Even a compromised server can't read your secrets.

3. Encrypt the secret, email it to yourself

On Windows:

echo "SERPER_API_KEY=..." | gpg --encrypt --recipient your@email.com > secret.gpg

Email secret.gpg to the address your agent checks.

4. Let the agent decrypt on the server

If you're comfortable with the server holding the private key (your own infrastructure — this is how mail servers work):

gpg --import private-key.asc
# now the agent can decrypt:
gpg --decrypt secret.gpg

Or keep the private key only on Windows and decrypt manually — the agent just sees "new encrypted email arrived."

The exchange protocol

Channel Allowed
Telegram Discussion, tasks, links — NO secrets
GPG email API keys, passwords, tokens — encrypted AND signed

Bonus: signing

Encrypting is half the story. Signing proves who sent the message:

gpg --sign --encrypt --recipient you@email.com file

Kleopatra then shows "Good signature" instead of "You cannot be sure who encrypted this message."

What I wish I'd done from day one

  1. Generated the GPG key pair before the first API key existed
  2. Never pasted a key into Telegram
  3. Routed all secrets through encrypted email
  4. Rotated the two keys I'd already exposed (Serper, Parallel)

The takeaway

Your agent's chat is a database. Your secrets don't belong in it.

Ten minutes of GPG setup — a public key on the server, a private key in Kleopatra, encrypted email between them — and you can exchange secrets with your agent without ever putting them in a chat log.