When developers talk about getting a “Telegram API key,” they are usually looking for one of two different things: an API ID and API Hash pair for building a client or user-account integration over Telegram’s MTProto protocol, or a Bot Token for running a standard Telegram bot over HTTPS. Picking the right credential upfront saves hours of debugging against the wrong interface.
1. API ID & API Hash vs. Bot Token
Telegram does not issue a single universal “API key.” Instead, the credential you need depends on which identity your code will act as:
| Feature | api_id + api_hash (Client / MTProto API) |
Bot Token (Telegram Bot API) |
|---|---|---|
| Where you get it | my.telegram.org under API development tools |
@BotFather inside Telegram using /newbot |
| Account identity | Authenticates a client app and authorizes a user account (or session) | Authenticates a dedicated bot account with a bot badge |
| Transport / Stack | MTProto protocol (often via libraries like Telethon, Pyrogram, GramJS, or TDLib) | Simple HTTPS REST/webhook requests to api.telegram.org |
| Best fit | Custom clients, user-account workflows, or full MTProto features | Chatbots, alerts, commands, menus, Mini Apps, and group bots |
| Key limitation | One api_id per phone number; requires user login/session handling |
Cannot initiate a direct message to a user who has never messaged the bot first |
Both options are free to obtain, and neither requires paying a per-message API fee—though both are subject to Telegram’s rate limits, spam/flooding rules, and API Terms of Service.
2. How to Get Your api_id and api_hash
If you are building an MTProto client or need user-level API credentials:
- Have an active Telegram account. Register and verify your phone number in an official Telegram app first.
- Sign in to Telegram’s developer portal. Go to
[https://my.telegram.org](https://my.telegram.org)and enter your phone number in full international format (for example,+15550192834). - Enter your login code. Check your active Telegram app for the verification code sent by Telegram and submit it on the portal.
- Open API development tools. Select API development tools on the portal.
- Fill out the application form. Provide an App title and Short name (alphanumeric characters), choose the target Platform (such as Desktop, Android, iOS, or Web), and submit.
- Copy and store your credentials. Telegram displays your numeric
api_idand secret alphanumericapi_hash. Save them immediately in a secure environment configuration rather than hardcoding them.
Note: Each phone number is generally limited to a single
api_id, andapi_id+api_hashidentify your application—they do not bypass user login or session authorization.
3. How to Get a Bot Token Instead
If you only need a standard bot, you do not need my.telegram.org:
- Open Telegram and search for
@BotFather(verify the official handle). - Send
/newbotand follow the prompts to choose a display name and a unique username ending inbot. - Copy the HTTP API token BotFather returns and treat it like a password.
4. Storing Credentials Safely & Fixing Common Snags
Treat your api_hash, bot token, login codes, and session files as sensitive secrets:
- Use environment variables. Store credentials in a local
.envfile (or your hosting platform’s secret manager) and add.envto.gitignoreso secrets never land in public repositories. - Keep secrets off the client. Never embed a bot token or
api_hashinside browser-delivered frontend code. - Avoid sample credentials. Do not copy placeholder API IDs or hashes from tutorials or open-source samples for real or public applications.
- Troubleshoot portal hiccups. If
my.telegram.orgthrows an error or blocks login, temporarily disable browser extensions (like ad blockers or VPNs), ensure your network/IP aligns cleanly with your account/region, and wait a few minutes if you hit a code-request flood limit.
Leave a Reply