Telegram does not issue a single “API key” like many REST services. Instead, which credential you need depends on what you are building:
- Client API (
api_idandapi_hash): Required when building a custom Telegram client,Telegram’s proprietary messaging protocol for client-server communication. integration, or a user-account script (using libraries like Telethon or Pyrogram). Each phone number can have only oneapi_idconnected to it. - Bot API (Bot Token): Required when building a standard Telegram bot that talks to Telegram’s HTTPS Bot API. You can create multiple bots and get a separate token for each one.
Getting Client API Credentials (api_id and api_hash)
- Log in to the developer portal: Open
[https://my.telegram.org](https://my.telegram.org)in a browser and sign in using the phone number linked to your active Telegram account. Enter the login code delivered inside your Telegram app. - Open API settings: Select API development tools on your account page.
- Register your application: Fill out the form with an App title and Short name (alphanumeric characters), choose your target Platform, and submit.
- Copy your credentials: Telegram displays your numeric
api_idand secretapi_hashimmediately. Save both in environment variables or a secret manager rather than hardcoding them in source files.
Note: If
my.telegram.orgthrows an error during creation, check that you are not routing traffic through a VPN or proxy that triggers anti-abuse blocks, and verify that your Telegram account is established and in good standing.
Getting a Bot API Token
If you only need a bot token rather than raw client credentials, you do not use my.telegram.org:
- Search for and open @BotFather inside Telegram.
- Send
/newbotand follow the prompts to enter a display name and a unique username ending inbot. - Copy the HTTP API token BotFather returns and store it securely.
Credentials and Security at a Glance
| Credential Type | Where You Get It | Best For | Key Rule to Remember |
|---|---|---|---|
api_id + api_hash |
my.telegram.org |
Custom clients, MTProto tools, user scripts | Tied to one phone number per api_id |
| Bot Token | @BotFather in Telegram |
Standard bots over the HTTP Bot API | Treat like a password; revoke via @BotFather if leaked |
Keep your api_hash and bot tokens out of public repositories, respect Telegram’s API Terms of Service to avoid account restrictions or bans, and keep your phone number active so you receive developer notices.
Leave a Reply