The short answer: BotFather issues the token
To get a Telegram bot token, open a chat with @BotFather, send /newbot, give the bot a display name, then a username that ends in "bot". BotFather replies immediately with the token, a string shaped like 110201543:AAHdqTcvCH1vGWJxfSeofSAs0K5PALDsaw. That string is the bot's only credential: whoever holds it controls the bot.
Last verified: November 2026 against Telegram's BotFather documentation and the Bot API reference.
The full sequence, start to finish:
- In any Telegram app, search for
@BotFatherand open the account with the blue verification check. t.me/BotFather opens it directly. Impersonator accounts with similar names exist, and they collect tokens. - Tap Start (or send
/start) to see the command list. - Send
/newbot. - When asked for a name, send the display name users will see in chats, for example
Acme Support. - When asked for a username, send a unique handle ending in
bot, for exampleacme_support_bot. - BotFather confirms with a message containing your bot's
t.melink and the HTTP API token. Copy the token into a secret store right away, not into a notes app or a chat with a colleague.
Telegram also ships a BotFather Mini App with the same functions in a graphical interface. The commands below work in both, and the docs describe the chat commands as the reference.
Display name vs username: the one choice you cannot undo
BotFather asks for two identifiers that look interchangeable and are not. The display name is cosmetic and editable. The username is permanent.
| Display name | Username | |
|---|---|---|
| Where it shows | Chat header, contact details, notifications | Search, @mentions, t.me/<username> links |
| Rules | Free text; setMyName accepts 0-64 characters | 5-32 characters, Latin letters, digits and underscores, case-insensitive, must end in bot |
| Example | Acme Support | acme_support_bot or AcmeSupportBot |
| Change later? | Yes: /setname or the setMyName method | No. Telegram's docs say the username cannot be changed after creation |
Two rejections come up constantly at this step. The username is taken: usernames are global across Telegram, so short generic names are long gone, and adding your brand plus a function (acme_orders_bot) usually works. It does not end in "bot": the suffix is mandatory, in any case (tetris_bot and TetrisBot are both valid, per the docs).
Because the username lives in every link you print, every QR code and every /command@username in a group, treat it like a domain name. If you need a test bot, create a second bot with a second username rather than renaming the production one later, which you cannot do anyway.
What the token is made of, and the "bot" prefix
A token has two halves separated by a colon:
110201543:AAHdqTcvCH1vGWJxfSeofSAs0K5PALDsaw
|_______| |__________________________________|
numeric secret part
bot IDThe part before the colon is numeric and identifies the bot; you will see the same number as the id field when you call getMe, which makes it a handy way to tell two bots' tokens apart without exposing the secret. The part after the colon is the secret. People sometimes call the whole string a "Telegram bot API key"; there is no separate API key, API secret or client ID for the Bot API. This token is all of it.
Every Bot API call puts the token in the URL path, prefixed with the literal word bot:
https://api.telegram.org/bot<TOKEN>/METHOD_NAME
https://api.telegram.org/bot110201543:AAHdqTcvCH1vGWJxfSeofSAs0K5PALDsaw/getMeThe docs call this out explicitly ("remember to prefix the word 'bot' to your token"), and it is still the most common copy-paste error. The two failure signatures are distinct:
| Response | Usual cause |
|---|---|
{"ok":false,"error_code":404,"description":"Not Found"} | The bot prefix is missing, the method name is misspelled, or the URL has an extra slash. See 404 Not Found. |
{"ok":false,"error_code":401,"description":"Unauthorized"} | The token is wrong, truncated, has whitespace or quotes in it, or was regenerated. See 401 Unauthorized. |
Libraries such as python-telegram-bot, aiogram, grammY and Telegraf add the prefix for you, so pass them the bare token. Passing bot123:ABC to a library produces botbot123:ABC in the URL and a 401 or 404 that looks baffling until you log the request path.
Finding the token for a bot you already created
Lost the original message? You do not need to create a new bot. BotFather keeps the token available to the bot's owner:
- Send
/mybotsto @BotFather. - Tap the bot in the list.
- Tap API Token. BotFather shows the current token.
Only the Telegram account that owns the bot can do this. If the bot was created by a former employee or an agency, the owner must either send you the token or use BotFather's ownership transfer (/mybots, select the bot, transfer ownership). Telegram's docs note two constraints: the recipient must have interacted with the bot at least once, and the transfer is permanent and hands over full control, including deleting the bot.
Transfer is the right fix for an orphaned business bot. Asking the old owner to paste the token in Slack leaves a live credential in a chat log forever and leaves them able to regenerate it at any time, which silently breaks your integration.
Test the token with getMe before writing any code
getMe is documented as "a simple method for testing your bot's authentication token". It needs no parameters:
curl -s https://api.telegram.org/bot<TOKEN>/getMeA valid token returns the bot's own profile:
{
"ok": true,
"result": {
"id": 110201543,
"is_bot": true,
"first_name": "Acme Support",
"username": "acme_support_bot",
"can_join_groups": true,
"can_read_all_group_messages": false,
"supports_inline_queries": false
}
}Three fields here are only returned by getMe and answer questions people usually debug the hard way:
can_read_all_group_messagesistrueonly if privacy mode is disabled. If it isfalse, your bot will not see ordinary group chatter, which is the default and usually correct.can_join_groupsreflects the/setjoingroupstoggle. If it isfalse, nobody can add the bot to a group.supports_inline_queriesreflects/setinline.
Check that username is the bot you expect. Teams with a staging bot and a production bot regularly ship the wrong token, and both pass getMe. If you would rather not use a terminal, the Telegram bot token checker runs getMe and getWebhookInfo from your browser and explains the result.
Using the token in python-telegram-bot, aiogram, grammY and Telegraf
Every major library takes the bare token (no bot prefix) and every one of them should read it from the environment, not from a string literal. These are the shortest correct starts, matching each library's own examples:
# python-telegram-bot (v20+)
import os
from telegram.ext import Application
app = Application.builder().token(os.environ["BOT_TOKEN"]).build()
app.run_polling()
# aiogram 3
import os
from aiogram import Bot, Dispatcher
bot = Bot(token=os.environ["BOT_TOKEN"])
dp = Dispatcher()
await dp.start_polling(bot) # inside an async main()
// grammY
import { Bot } from "grammy";
const bot = new Bot(process.env.BOT_TOKEN ?? "");
bot.start();
// Telegraf
import { Telegraf } from "telegraf";
const bot = new Telegraf(process.env.BOT_TOKEN ?? "");
bot.launch();
Fail fast when the variable is missing. os.environ["BOT_TOKEN"] raises immediately in Python; in Node, grammY's constructor throws Empty token! straight away, but Telegraf accepts a missing token and only fails on its first request. Add an explicit check at startup; it also narrows the type, so strict TypeScript accepts the token without a ?? "" fallback:
const token = process.env.BOT_TOKEN?.trim();
if (!token || !/^\d+:[\w-]+$/.test(token)) {
throw new Error("BOT_TOKEN is missing or malformed");
}
const bot = new Bot(token); // token is a string from here on
The .trim() is not decoration: a trailing newline from echo TOKEN > .env or a secrets-manager paste is the single most common reason a token that works in curl fails in the app, usually with 401 Unauthorized, or with 404 Not Found when the newline ends up encoded in the URL path. A value that is not even shaped like a token gets the longer 401 Unauthorized: invalid token specified. The pattern is a sanity check on shape only - getMe is still the real test.
One logging detail is worth copying from python-telegram-bot's own example bot: it raises the httpx logger to WARNING "to avoid all GET and POST requests being logged". Those request lines contain /bot<TOKEN>/, so at INFO or DEBUG level the token is written to every log line your bot produces. Check the equivalent setting for whatever HTTP client your library uses before you turn on verbose logging in production.
Finally, if two processes start with the same token and both poll, the second one kicks the first off with 409 Conflict: terminated by other getUpdates request; if one of them calls setWebhook while the other polls, the poller gets terminated by setWebhook request. Both are deployment problems, not token problems, and both disappear once each token has exactly one consumer.
Finish the setup in BotFather: profile, privacy and groups
A bot fresh out of /newbot has a name, a username and a token, and nothing else. Users who open it see an empty chat. Before you share the link, spend five minutes on the settings Telegram's BotFather guide lists, each of which also has a Bot API equivalent if you would rather keep them in code:
| BotFather command | What it sets | API method and limit |
|---|---|---|
/setdescription | The "What can this bot do?" text shown in an empty chat | setMyDescription, 0-512 characters |
/setabouttext | The short bio on the profile page, also sent when someone shares the bot | setMyShortDescription, 0-120 characters |
/setname | The display name | setMyName, 0-64 characters |
/setuserpic | The profile picture | Set in BotFather or on the bot's profile page |
/setcommands | The command menu shown when users type / | setMyCommands, up to 100 commands per list |
/setjoingroups | Whether the bot can be added to groups at all | Reflected in getMe as can_join_groups |
/setprivacy | Which group messages the bot receives | Reflected in getMe as can_read_all_group_messages |
/setinline | Inline mode (@your_bot query in any chat) | Reflected in getMe as supports_inline_queries |
The description, about text and name can all be localized: the API methods take a language_code, and each user automatically sees the translation for their app language, with the version set without a language code as the fallback. BotFather's guide also notes that changes may take a few minutes to take effect, so do not conclude a setting failed because the profile did not update instantly.
Two settings deserve a deliberate decision rather than the default. Groups: if the bot is a one-to-one support or sales assistant, turn /setjoingroups off so nobody can add it to a group where it will receive messages it was never designed for. Privacy: leave privacy mode on unless the bot genuinely has to read every group message; the commands it needs to see still arrive, as our guide to Telegram bot commands explains in detail. Copy for the description is easier to get right with the Telegram text formatter, and buttons for the first message with the keyboard builder.
One command to treat with care: /deletebot deletes the bot and frees its username, and BotFather's guide says it cannot be undone. Every link, QR code and integration that used that username or token stops working.
How to revoke a Telegram bot token and issue a new one
If a token leaks, regenerate it. Telegram's docs name the command: "If your existing token is compromised or you lost it for some reason, use the /token command to generate a new one." BotFather asks which bot, then replies with a fresh token. In the /mybots menu, the API Token screen offers the same action as a button. Older tutorials refer to a /revoke command; Telegram's documentation says the live command list in BotFather (type / in the chat) is the authoritative reference, so use whichever your client shows.
What happens next matters more than the command:
- The old token stops authenticating. Every process still using it starts receiving
401 Unauthorized. There is no grace period to plan around, so have the new value ready to deploy before you regenerate. - The bot keeps its identity. Same username, same numeric ID, same chats and subscribers. Only the secret half of the token changes.
- Update every consumer. Production, workers, cron jobs, CI secrets, any third-party platform the token was pasted into. A single forgotten worker using the old token will log 401s that are easy to mistake for an outage.
- Re-check delivery. After deploying, call
getWebhookInfoand confirm theurlandpending_update_countlook right, or run the Telegram webhook checker.
Regenerate on a schedule only if you have automated the rollout. Regenerating by hand "for hygiene" is a reliable way to take a working bot offline at 5 p.m. on a Friday.
One special case: if you build a manager bot with Bot Management Mode, the Bot API exposes getManagedBotToken to fetch a managed bot's token and replaceManagedBotToken to revoke it and generate a new one, so rotation can be automated without BotFather.
Storing the token so it never ends up somewhere public
Telegram's own tutorial says to "treat it like a password" and suggests a settings file or environment variables rather than source code. In practice that means:
| Environment | Where the token should live |
|---|---|
| Local development | A .env file listed in .gitignore, loaded at startup |
| Containers / PaaS | The platform's secret or environment variable store, injected at runtime |
| Cloud production | A secrets manager (AWS Secrets Manager, GCP Secret Manager, Vault), read at boot |
| CI | Encrypted CI secrets, masked in logs |
| Browser, mobile app, Mini App front end | Nowhere. Anything shipped to a client can be extracted |
The token sits in the URL path of every API call, which creates a leak path people miss: request logs. HTTP client debug logging, reverse proxy access logs, APM tools and error trackers that capture outbound URLs will all record /bot<TOKEN>/sendMessage unless you redact it. Grep your log pipeline for api.telegram.org/bot once and add a scrubbing rule.
Two related secrets are worth setting up at the same time:
- Webhook secret.
setWebhookaccepts asecret_token(1-256 characters,A-Z,a-z,0-9,_and-). Telegram then sends it in theX-Telegram-Bot-Api-Secret-Tokenheader on every update, so your endpoint can reject requests that did not come from your webhook. Do not reuse the bot token for this value. - A separate test bot. The docs recommend testing on a different bot account with its own token, so development traffic never touches production users or credentials.
Before trusting any third-party bot platform or browser tool with a production token, check what it does with it: whether calls go straight from your browser to Telegram, or whether the token is stored server-side. When in doubt, test with a throwaway bot.
What never to do with a bot token
A Telegram bot token is not scoped. There are no read-only tokens and no per-method permissions: the holder can send messages as your bot to every user who started it, read every update, change the webhook to their own server, and edit the bot's commands and profile. That makes the list of mistakes short and absolute:
- Do not paste it in public. GitHub issues, Stack Overflow questions, Discord help channels, screen recordings and screenshots of BotFather all leak tokens. Replace it with
<TOKEN>before sharing anything. - Do not commit it. Removing the line in a later commit does not remove it from history. If a token was ever committed to a shared repo, regenerate it.
- Do not embed it in client code. A website that calls
api.telegram.orgfrom JavaScript, or a mobile app with the token in its bundle, hands the bot to anyone who opens developer tools. - Do not share one token across environments. One token, one deployment. Two processes polling the same token produce the 409 conflict, and a dev laptop running the production token will steal its updates.
- Do not send it to contractors. Add them to the code, not the credential, or transfer ownership deliberately.
If you suspect a leak, the response is the same every time: run /token, deploy the new value, call getWebhookInfo to confirm the webhook still points to your server and not someone else's, and review getMyCommands in case the bot's menu was changed.
Test environment and local Bot API server: tokens that live elsewhere
Most teams only need a second bot for testing, which is what Telegram's testing guidance recommends: create another bot with BotFather and run a second instance of your code against its token. Note one consequence from the same page: file_id values are tied to a single bot, so a test bot cannot reuse a production database of file IDs and must upload media itself.
Two less common setups change where a token works, and both confuse people who meet them for the first time.
The dedicated test environment
Telegram runs a separate test environment with its own accounts and its own BotFather. You log in to it with a hidden option in the Telegram apps (Telegram Desktop: Settings, then Shift + Alt + right-click "Add Account" and choose Test Server), create a new account and a new bot there, and call the API with /test/ after the token:
https://api.telegram.org/bot<TEST_TOKEN>/test/getMe
The environment is completely separate from production, so a production token does not work against the test path and a test token does not work against the normal one - a mismatch shows up as a 401 that looks like a bad token. The test environment allows plain HTTP links for Mini Apps and Login URLs, but Telegram warns that flood limits are not raised there and may at times be stricter, so it is not a way around 429 Too Many Requests.
A local Bot API server
Telegram publishes the Bot API server source so you can run it yourself, which lifts the 20 MB download and 50 MB upload limits (to unlimited and 2,000 MB), allows plain-HTTP webhooks on any port and local IPs, and raises max_webhook_connections to 100,000. The token stays the same, but the move has an order:
- Call
logOuton the cloud API. The Bot API reference says you must do this before running the bot locally, "otherwise there is no guarantee that the bot will receive updates". - Point your library at the local server's URL and log in there.
- Know that the exit is slow: after
logOutyou cannot log back in to the cloud Bot API server for 10 minutes. Moving between two local servers usescloseinstead, after deleting the webhook.
The full table of official versus local limits is on our Telegram limits page. For most bots the cloud API is the right answer, and Telegram says as much: the majority of bots are fine on the default configuration.
Next step: choose getUpdates or setWebhook
With a working token, the bot still receives nothing until you pick one of the two update delivery methods. They are mutually exclusive: the docs state you cannot receive updates with getUpdates while an outgoing webhook is set.
| getUpdates (long polling) | setWebhook | |
|---|---|---|
| How it works | Your process asks Telegram for new updates in a loop | Telegram POSTs each update to your HTTPS URL |
| Needs a public URL | No | Yes, HTTPS on port 443, 80, 88 or 8443 |
| Best for | Local development, single-instance bots, firewalled hosts | Production, serverless, horizontally scaled backends |
| Main failure mode | Two pollers on one token (409 conflict) | Endpoint errors or TLS problems that pile up undelivered updates |
| Switch with | deleteWebhook before polling | setWebhook with url; empty string removes it |
A minimal first test with polling needs nothing but the token:
curl -s "https://api.telegram.org/bot<TOKEN>/getUpdates?timeout=30"Send your bot a message from your phone and the update appears in the response, including chat.id, which you need for sendMessage. From there:
- Generate shareable
t.melinks with a start payload using the Telegram link generator. - Check message sizes, polling and webhook ceilings on the Telegram limits page before you design around them.
- If the bot connects but stays silent, work through why a Telegram bot is not responding, which starts from
getWebhookInfo. - Look up any error string you hit in the Telegram Bot API error codes guide.
If you would rather not run the webhook server at all, a hosted platform can take the token and handle delivery for you, and you can try one free before deciding. Either way, the token you just created is the only thing that ties the bot to you, so the storage rules above apply regardless of who runs the code. A webhook endpoint is also where most new bots first break; the Telegram error directory lists every bad webhook message, such as HTTPS url must be provided, with its fix.
Where Telegram earns its place as a business channel
A token, a webhook and an afternoon are all it takes to put a bot in front of Telegram's users, which is why Telegram shows up as a real customer channel rather than a side project in a few industries. Ecommerce stores use it for order updates and cart recovery, where a t.me deep link replaces an app install; logistics teams use it because drivers and dispatchers already live in Telegram in many regions; education providers run cohort announcements and Q&A through it; media and publishing companies distribute content and run reader communities; nonprofits coordinate volunteers at low cost; and tech companies often make it the default support channel for a technical audience.
Once the bot is live, BotFather keeps an eye on it too. For popular bots, Telegram's features guide says BotFather sends status alerts when the reply rate drops abnormally - for example when the bot stops answering incoming private messages or callback queries - at most one alert per bot per hour by default. An alert like that is usually the first sign that a deploy shipped the wrong token. The chat ID finder and link generator cover the next two things most business bots need, and our guides to Telegram for business and Telegram bots for customer support cover the conversation design.
Avoiding this class of problem entirely
The token is the easy part. What follows it - the webhook lifecycle, polling conflicts, retries, rate limits, log redaction and token rotation across every worker - is the work that actually takes time, and it is the same work for every bot on the platform. Every other chat platform makes you pay a version of the same tax under a different name: Discord has its own token and intents (see how to get a Discord bot token), Slack has three token types with different scopes (see Slack bot token types), and WhatsApp adds Meta's webhook handshake (see Meta webhook verification failed).
A managed platform takes that layer away. With Conferbot's Telegram channel, available on every plan including Free, you paste the token BotFather gave you and build the conversation in a visual flow editor - webhook registration, retries, rate limiting and message formatting are handled for you, and the token is stored server-side rather than in your code. The same flow deploys to WhatsApp, Discord, Slack and a website widget without rewriting it per platform, with every conversation in one omnichannel inbox. If you would rather skip the token entirely, how to make a Telegram bot without coding walks through the no-code route, including one-click setup through Telegram's Managed Bots.
Start free with Conferbot - the free plan includes 600 conversations a month and needs no credit card, so you can have the same flow running on a second channel this afternoon.
If you are setting up a bot by hand today, the order is simple: create it, test the token with getMe, store it as a secret, then pick polling or a webhook. If you find yourself doing that for a third channel, that is the point where a platform starts paying for itself.
Was this article helpful?
Build and deploy in 10 minutes. No coding needed.
How to Get a Telegram Bot Token from BotFather (and Keep It Safe) FAQ
Everything you need to know about chatbots for how to get a telegram bot token from botfather (and keep it safe).
About the Author
The Conferbot team writes about building, deploying, and improving AI chatbots.
View all articlesRelated Articles
From the reference shelf
Fact-checked reference pages and free tools for the platform this article covers.