Skip to content

Instantly share code, notes, and snippets.

@arun-gupta
Last active March 26, 2026 21:01
Show Gist options
  • Select an option

  • Save arun-gupta/a8e64afd67794160841cf1f7732a2243 to your computer and use it in GitHub Desktop.

Select an option

Save arun-gupta/a8e64afd67794160841cf1f7732a2243 to your computer and use it in GitHub Desktop.
Connecting OpenClaw to Claude and Telegram

Connecting OpenClaw to Claude and Telegram

In the previous blog we got OpenClaw running in Docker. Now, we give it a brain and a voice. The brain is Claude via the Anthropic API. The voice is Telegram. By the end, you will be chatting with Clawde from your phone.

Here is the full stack we are building:

Telegram (your phone)
      ↓
@askclawde_bot (Telegram Bot)
      ↓
OpenClaw Gateway (Docker container)
      ↓
Claude via Anthropic API (the brain)

Create a Dedicated Anthropic API Key

It is strongly recommended to create a dedicated API key for OpenClaw rather than reusing one from another project. This gives you:

  • Blast radius control: if OpenClaw burns through credits unexpectedly, it won't affect your other projects
  • Easy revocation: you can revoke OpenClaw's key without disrupting anything else
  • Usage tracking: OpenClaw's usage shows up separately in the Anthropic console, making costs easy to monitor
  • Security: if the key is ever exposed in logs or config files, the damage is contained

Go to console.anthropic.com, navigate to API Keys, and create a new key named clawde or openclaw-local.

Purchase Credits

Anthropic credit grants (free promotional credits) are not sufficient for API access: you must purchase credits directly. Go to API Keys → Billing → Buy credits and add a small amount (e.g. $5) with a credit card.

Set a Monthly Spend Limit

New accounts default to a $0 monthly spend limit, which blocks all API access regardless of your credit balance. Go to Limits and set it to a reasonable amount, e.g. $20 to match your purchased credits.

Verify Credits and Limits

  • Plans & Billing: confirm purchased credits are available (credit grants alone are not enough)
  • Limits: confirm monthly limit is greater than $0
  • API Keys → Last used at: shows Never until the first successful API call; use this to confirm the key is working

Add the API Key to OpenClaw

Run the following command to configure the Anthropic API key for the main agent:

docker exec -it openclaw node openclaw.mjs agents add main

This will prompt you to select a model/auth provider: OpenClaw supports a wide range of providers including Anthropic, OpenAI, Google, Mistral, Ollama (fully local/offline), OpenRouter, and many more. Select Anthropic, then when prompted for the auth method choose Anthropic API key: this is the standard, long-lived credential from the Anthropic console. The "Anthropic token (setup-token)" option is a temporary token for device-based auth flows and adds unnecessary complexity for a self-hosted setup.

The key is stored in:

~/openclaw-config/agents/main/agent/auth-profiles.json

Because ~/openclaw-config is mounted as a volume, the key persists across container restarts.


Verify the API Key

Before testing via the chat UI, verify the API key works directly against the Anthropic API:

KEY=$(docker exec openclaw cat /home/node/.openclaw/agents/main/agent/auth-profiles.json | \
  python3 -c "import sys,json; d=json.load(sys.stdin); print(list(d['profiles'].values())[0]['key'])")

curl -s https://api.anthropic.com/v1/messages \
  -H "x-api-key: $KEY" \
  -H "anthropic-version: 2023-06-01" \
  -H "content-type: application/json" \
  -d '{"model":"claude-3-haiku-20240307","max_tokens":10,"messages":[{"role":"user","content":"hi"}]}'

A successful response will contain a content field. If you see "Your credit balance is too low", check that you have purchased credits and your monthly spend limit is greater than $0.

image

Connect OpenClaw to Telegram

After configuring the API key, you can connect OpenClaw to a messaging platform. OpenClaw supports a wide range of channels including Telegram, WhatsApp, Discord, Slack, Signal, iMessage, Microsoft Teams, Matrix, and many more: OpenClaw can meet you wherever you already communicate.

In this blog we'll use Telegram: it's the easiest to set up and keeps your other personal accounts completely separate, limiting the blast radius if something goes wrong.

Step 1: Create a Telegram Bot

Open Telegram and search for @BotFather. Send it:

/newbot

BotFather will ask for:

  1. A display name: e.g. Clawde
  2. A username (must end in bot): e.g. askclawde_bot

BotFather will then give you a bot token. Keep it handy.

Step 2: Configure the Bot in OpenClaw

Run the agents add main command again and this time select Telegram (Bot API) as the channel. Paste the bot token when prompted.

When asked about DM access policies, select No (default pairing policy is fine). When asked about routing bindings, select No.

docker exec -it openclaw node openclaw.mjs agents add main

Step 3: Start the Bot in Telegram

Open Telegram, search for your bot (e.g. @askclawde_bot), and tap Start. OpenClaw will respond with a pairing code:

OpenClaw: access not configured.

Your Telegram user id: <your-id>
Pairing code: XXXXXXXX

Ask the bot owner to approve with:
openclaw pairing approve telegram XXXXXXXX

Step 4: Approve the Pairing

Run the following command with the pairing code from Telegram:

docker exec openclaw node openclaw.mjs pairing approve telegram <pairing-code>
image

Step 5: Chat with OpenClaw

Send any message to the bot in Telegram: OpenClaw will now respond using Claude via the Anthropic API.

image

Lessons Learned: Token Economics

A simple weather question on Telegram cost $0.13. That may seem small, but it adds up quickly. What looks like a single question actually involves multiple exchanges: OpenClaw asks for your location, fetches the data, formats the response, and maintains conversation history all of which burn tokens.

OpenClaw defaults to anthropic/claude-opus-4-6, which is the most capable but also the most expensive Claude model. For everyday tasks like weather queries, switching to a smaller model can reduce costs significantly:

Model Best for
claude-opus-4-6 Complex reasoning, coding, long documents
claude-sonnet-4-6 Balanced performance and cost
claude-haiku-4-5 Simple queries, fast responses, low cost

To change the model, update openclaw.json:

{
  "gateway": {
    "bind": "lan",
    "model": "anthropic/claude-sonnet-4-6"
  }
}

Or set it per agent when running agents add main. Match the model to the task not every question needs Opus.


Chat via Browser

OpenClaw is also accessible directly from the browser without any messaging app:

http://127.0.0.1:18789/chat?session=agent%3Amain%3Amain
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment