Telegram Bot Token: How to Get It, Find It Again, Check It and Keep It Safe
A Telegram bot token is the secret key that authorizes every Bot API request your bot makes. You get it from @BotFather when you create a bot with /newbot, view it again later under /mybots → API Token, check it with getMe, and revoke it in seconds if it leaks. Below are all four tasks with copy-paste commands, plus how to store the token safely and why automation tools ask for a token and a chat id.
What a Telegram bot token looks like (example)
A token has two parts separated by a colon: the bot's numeric id and a secret string. Telegram's documentation uses 123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11 as an example; this guide uses the placeholder 123456789:AAEexampleTokenReplaceWithYours. In every request the token follows the literal word bot: https://api.telegram.org/bot<token>/METHOD_NAME.
Whoever holds the token has full control of the bot: they can read its incoming messages, send messages in its name, and change its webhook, commands and description. Don't confuse it with api_id and api_hash, which are credentials for apps built on the MTProto Telegram API, not for bots.
How to get a Telegram bot token
- Open @BotFather and send
/newbot. - Enter a display name, then a username: 5–32 characters, Latin letters, digits and underscores, ending in
bot. - Copy the token from BotFather's reply.
The full walkthrough, from BotFather to a first message, is in how to create a Telegram bot. For experiments, create a separate test bot with its own token, so mistakes never reach the users of your production bot.
Find the token of an existing bot
- Send
/mybotsto @BotFather. - Choose the bot from the list.
- Press API Token. BotFather shows the bot's current token.
Don't use /token to look up a token: it generates a new one. Only the account that owns the bot sees it in /mybots. If a colleague created the bot, they can hand it over via /mybots → the bot → Transfer Ownership; the new owner must have interacted with the bot at least once.
Check a Telegram bot token with getMe
getMe needs no parameters, which makes it the standard token check:
curl "https://api.telegram.org/bot123456789:AAEexampleTokenReplaceWithYours/getMe"
A valid token returns "ok": true and the bot's User object, so you also see which bot the token belongs to:
{"ok": true, "result": {"id": 123456789, "is_bot": true, "first_name": "Weather Alerts", "username": "weather_alerts_bot"}}
An invalid token returns:
{"ok": false, "error_code": 401, "description": "Unauthorized"}
Typical causes of 401: a missing or extra character, a space, line break or quotes picked up while copying, or a token that has been revoked or regenerated. A 404 Not Found points to the URL itself, most often a missing bot before the token.
The same check in Python, handy as a startup test for your bot:
import os
import requests
token = os.environ["BOT_TOKEN"].strip()
data = requests.get(f"https://api.telegram.org/bot{token}/getMe", timeout=10).json()
if data["ok"]:
print("Token OK for @" + data["result"]["username"])
else:
print("Token rejected:", data["error_code"], data["description"])
Prefer a browser? Paste the token into getMe in the Bot API Tester and press Execute. The token is kept only in your browser's localStorage, and the request goes straight to api.telegram.org.
Revoke a leaked token
Treat the token as compromised if it was committed to a repository, shown in a screenshot or video, pasted into a chat, or shipped in front-end code. Deleting the commit or message is not enough, because someone may already have copied it. Revoke it:
- Send
/revoketo @BotFather and choose the bot, or open/mybots→ your bot → API Token → Revoke. - Copy the new token. The old one stops working.
- Replace it everywhere: server environment variables, CI secrets, n8n credentials, AI assistant configs. Then restart those services.
- Run
getMewith the new token, andgetWebhookInfoto make sure the webhook still points to your server and not to a URL someone else set.
Keep your bot token secret
- Load the token from an environment variable or a secret manager; never hardcode it.
- Add
.envto.gitignorebefore the first commit. - Never put it in a Mini App, website JavaScript or a mobile app: anything shipped to users can be extracted. Call the Bot API from your backend.
- The token is part of every request URL, so don't log full request URLs, and mask the token in error reports.
- Use one bot per project or integration, so revoking one token doesn't break the rest.
# .env (listed in .gitignore)
BOT_TOKEN=123456789:AAEexampleTokenReplaceWithYours
import os
TOKEN = os.environ["BOT_TOKEN"] # export it, or load .env with python-dotenv
// run with: node --env-file=.env bot.js (Node.js 20.6+)
const TOKEN = process.env.BOT_TOKEN;
Telegram bot token and chat id for n8n and AI assistants
Automation platforms such as n8n and AI assistants that connect to Telegram, such as OpenClaw, usually ask for two values:
- Bot token: lets the tool act as your bot. Create a dedicated bot for each tool and check the token with
getMebefore pasting it. - Chat id: tells the tool where to send messages or whose messages to accept. Message your bot, call
getUpdatesand readmessage.chat.id; how to get a Telegram chat id also covers groups, channels and topics.
Look up the chat id before you connect the tool. Once the tool receives updates for the bot itself, through a webhook or its own polling, your manual getUpdates calls conflict with it and fail with 409 Conflict. How webhooks work is explained in how to set up a Telegram bot webhook.
Troubleshooting token errors
| Symptom | Likely cause | Fix |
|---|---|---|
401 Unauthorized | Wrong, incomplete or revoked token | Copy it again from /mybots → the bot → API Token |
404 Not Found | No bot before the token, or a typo in the method name | Use https://api.telegram.org/bot<token>/getMe |
| Works in curl, fails in your app | Environment variable not loaded, or stray whitespace or quotes | Strip the value and check how .env is loaded |
| 401 right after a revoke | A service still uses the old token | Update every place the token is stored |
409 Conflict | Another process receives updates for this token | Stop the other poller, or call deleteWebhook if a webhook is set |
Frequently asked questions
How do I get a Telegram bot token?
Open @BotFather, send /newbot, then choose a display name and a username ending in bot. BotFather replies with the token, which looks like 123456789:AAEexampleTokenReplaceWithYours.
Where can I find the token of my existing bot?
Send /mybots to @BotFather, choose the bot and press API Token. Don't use /token for this: it generates a new token instead of showing the current one.
How do I check if a Telegram bot token is valid?
Call https://api.telegram.org/bot<token>/getMe. A valid token returns "ok": true with the bot's id and username; 401 Unauthorized means the token is wrong or has been revoked.
What does a Telegram bot token look like?
Two parts separated by a colon: the bot's numeric id and a secret string, for example 123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11 from Telegram's docs. In requests it follows the word bot, as in /bot123456:ABC…/getMe.
What should I do if my bot token leaked?
Revoke it right away: send /revoke to @BotFather, or open /mybots → your bot → API Token → Revoke. The old token stops working, so put the new one everywhere the bot runs.
Why do n8n and AI assistants ask for a bot token and a chat id?
The token lets the tool act as your bot, and the chat id tells it which chat to send messages to or accept them from. You get the chat id by messaging your bot and calling getUpdates.
Related guides
How to Create a Telegram Bot: Step by Step with BotFather and Python
How to create a Telegram bot step by step: register it with @BotFather, get the token, test it with getMe and send a first message with curl or Python.
Telegram Bot API 10.0–10.3: Rich Messages, Ephemeral Messages, Guest Mode and More
What's new in Telegram Bot API 10.0–10.3: guest mode, rich messages, streamed drafts, ephemeral messages, join request queries, with JSON examples.
Telegram Bot API Limits: Rate Limits, 429 Errors, File Sizes and Message Length
Telegram Bot API rate limits explained: 30 msg/s, 1 msg/s per chat, 20/min in groups, handling 429 retry_after, plus file size and message length limits.
How to Send a Message with the Telegram Bot API (sendMessage)
Telegram Bot API send message guide: sendMessage with curl, Python and JavaScript, HTML and MarkdownV2 formatting, inline buttons and error fixes.
How to Set Up a Telegram Bot Webhook: setWebhook, Secret Token and Troubleshooting
Set up a Telegram bot webhook: setWebhook URL requirements, secret_token header check, getWebhookInfo debugging, deleteWebhook and fixes for n8n.
How to Get a Telegram Chat ID for a User, Group, Channel or Topic
How to get a Telegram chat ID for a user, group, supergroup, channel or forum topic with getUpdates, plus fixes for an empty result and 409 Conflict.
How to Test a Telegram Mini App: From Browser Mock to Real Telegram
Test a Telegram Mini App step by step: browser mock mode, localhost via HTTPS tunnel, test environment, DevTools per platform, initData validation.