Telegram API Keys Explained: Bot Tokens vs. Client Credentials
When people search for a “Telegram API key,” they usually want to automate notifications, build a chatbot, or connect a custom script to Telegram. The first surprise is that Telegram does not issue a single universal key. Depending on whether you are building a bot or connecting as a user account, you will work with two completely different credential types:
- Bot API Token (
123456789:AAH...) — Issued by@BotFatherfor bots interacting via Telegram’s HTTP Bot API. - Client API Credentials (
api_idandapi_hash) — Issued onmy.telegram.orgfor custom clients or scripts using the MTProto protocol / TDLib as a user account.
Choosing the right one upfront saves hours of confusion and keeps your account safe.
1. Bot API Token (For Most Bots, Alerts, and Automations)
If you want a script to ping your phone when a server goes down, post updates to a channel, or power a chat assistant, you only need a Bot API Token. Telegram does not charge for creating bots or tokens.
How to Get a Bot Token
- Open Telegram and search for
@BotFather(confirm the verified blue checkmark so you do not interact with a lookalike account). - Tap Start or send
/start. - Send
/newbotand follow the prompts:- Display name: What users see in the chat header (can be changed later with
/setname). - Username: Must be 5–32 characters using Latin letters, numbers, and underscores, end with
bot(for example,my_alert_bot), and be unique across Telegram.
- Display name: What users see in the chat header (can be changed later with
- Copy the token returned by BotFather—it looks like
110201543:AAHdqTcvCH1vGWJxfSeofSAs0K5PALDsaw(a numeric bot ID, a colon, and an authentication string).
Sending Your First Message
A bot token authenticates your bot, while a chat_id tells Telegram where to deliver a message. To find your chat ID, message your new bot in Telegram first so it has an active conversation to inspect, then call getUpdates over HTTPS using your token ([https://api.telegram.org/bot](https://api.telegram.org/bot)<YOUR_TOKEN>/getUpdates) and read the "chat":{"id": ...} value. Private chats use positive numbers; groups, supergroups, and channels use negative numbers (often starting with -100).
Once you have both values, sending a message is a standard HTTP POST request to [https://api.telegram.org/bot](https://api.telegram.org/bot)<YOUR_TOKEN>/sendMessage with chat_id and text.
2. api_id and api_hash (For User-Account Clients and MTProto)
Some libraries and workflows—such as custom clients built on TDLib or user-level automation frameworks—ask for an api_id (an integer) and an api_hash (a string) instead of a bot token. These identify your application when authenticating a Telegram user account over MTProto.
How to Get api_id and api_hash
- Visit
my.telegram.orgin a browser and enter your phone number in international format (for example,+8210...without the leading0). - Check your active Telegram app for the login confirmation code sent by Telegram’s official notification chat, then sign in. (Treat this code carefully—messages on
my.telegram.orgwarn not to share it, as it grants sensitive account-level access.) - Click API development tools (avoid clicking Delete account on the landing screen).
- Fill in your App title and Short name (5–32 alphanumeric characters) and submit to receive your
api_idandapi_hash.
A few practical rules apply here: each phone number maps to a single api_id pair; placeholder credentials copied from public tutorials are rate-limited; and automated actions running under a personal account are monitored closely against Telegram’s API terms, where spam or bulk messaging can trigger account restrictions.
Bot Token vs. Client API Credentials at a Glance
| Feature | Bot API Token | Client API (api_id + api_hash) |
|---|---|---|
| Where you get it | @BotFather in Telegram |
my.telegram.org |
| Best for | Alerts, webhooks, chatbots, channel posters | Custom clients, TDLib / MTProto user scripts |
| Acts as | A standalone bot account | Your personal user account |
| Main limitation | Cannot initiate cold DMs before a user messages the bot | Stricter anti-abuse scrutiny on user-account automation |
Security & Operational Habits That Prevent Headaches
A Telegram bot token acts like a password for that bot: anyone holding it can read incoming updates and send messages as your bot. A user-account api_id and api_hash pair is even more sensitive because it ties directly to your personal account session.
- Keep secrets out of source code: Store tokens and API credentials in environment variables or a secret manager rather than hardcoding them into scripts or committing
.envfiles to Git. Platforms like GitHub actively scan pushes for Telegram bot token patterns. - Rotate immediately on exposure: If a bot token ever lands in a public repo, chat log, or screenshot, open
@BotFather, run/revoke(or open/mybotsand replace the token), update your deployment, and verify that the old token is rejected. - Mind rate limits and hosting: A basic script on your laptop works fine for personal alerts, while a bot that needs 24/7 uptime or serves many users belongs on a cloud host or worker with proper error handling and respect for Telegram’s rate limits.
Start with a simple notification bot first—once you see a real-time alert pop up on your device from a few lines of code or an automation tool, the whole architecture clicks into place.
Leave a Reply