Software configuration

How to get and configure api_id and api_hash for Telethon

Find Telethon credentials in the Telegram developer portal, check integer and string formats, and distinguish application ERROR from configuration and sign-in problems.

GetTGAPI editorial teamUpdated

Quick answer: Telethon's api_id and api_hash come from a Telegram developer application, normally configured as an integer ID and a string Hash. They are not a phone number, bot token or GetTGAPI access code. Contact support for application-stage ERROR; check configuration first if you already have credentials.

Which values do the code fields refer to?

api_id is the portal's API ID; api_hash is its API Hash. Searches for “Telethon apiid” or “Telegram apihash” commonly refer to the same pair.

Telethon's introduction obtains application credentials through the developer portal and uses them to initialize a client. This guide follows the current stable 1.45.0 documentation; use matching documentation for another major version. Telethon Signing In

Where do I obtain them?

Use an existing Telegram account you are authorized to operate and open API development tools at my.telegram.org. Read existing app details before creating anything. See the API ID application walkthrough.

ERROR, a failed form submission or [object Object] at this point is still an application-stage issue. Contact gettgapi.com/en/help#contact with the stage. There is no need to hand over your program or account session first.

Check the configuration before applying again

Setting Expected input Common mix-up
api_id The numeric application ID you obtained Phone number, bot user ID, access code or a whole labelled line
api_hash Its matching, complete Hash string Missing characters, whitespace or a Bot Token
Session name or file Local session managed by your program Treating it as API Hash or sharing it publicly
Login code and two-step password Account authorization when requested Mixing portal confirmation and client sign-in codes

Repository example values are not your credentials. Do not paste complete configuration into public troubleshooting messages.

A local-only Python format check

Set TG_API_ID and TG_API_HASH through your own environment or secret manager. Keep real values out of public repositories. This example only reads and checks configuration; it does not connect to Telegram, request a code or sign in.

import os
import re

raw_id = os.environ.get("TG_API_ID", "").strip()
raw_hash = os.environ.get("TG_API_HASH", "").strip()

if not re.fullmatch(r"[0-9]+", raw_id) or int(raw_id) <= 0:
    raise ValueError("TG_API_ID must be a positive integer")
if not re.fullmatch(r"[0-9a-fA-F]{32}", raw_hash):
    raise ValueError("Check the complete API Hash copied from the portal")

api_id = int(raw_id)
api_hash = raw_hash
print("Local format check passed; credentials were not printed")

The Hash check uses the usual 32-character hexadecimal portal format. If your value differs, verify it against the official application details. Passing a format check does not prove the pair is matching, valid or authorized for a user. Follow your Telethon version's instructions for client initialization and authorization.

Separate three types of failure

  1. Web application failure: No ID and Hash yet. Follow portal ERROR checks and ask support about application assistance if needed.
  2. Configuration failure: Results exist, but the program reports conversion errors, missing environment variables or API_ID_INVALID. Check the actual values read by the process and the matching pair. See API_ID_INVALID.
  3. User authorization: The program requests a login code or two-step password. A different developer credential pair cannot replace account verification or guarantee a sign-in fix.

For example, variables set in one terminal may still be missing in a separate service process. Applying again will not pass configuration into that process.

Can a bot token replace api_hash?

Do not substitute one for the other. Telethon's bot sign-in example initializes the client with API ID and Hash, then supplies a Bot Token separately. Direct HTTP Bot API integrations follow their own token-based instructions. Telethon bot sign-in

Choose a practical use case after configuration

For auto replies or scheduled notifications, read message automation and deduplication. For personal records, see chat backup and search. The Telegram API use-case overview covers other routes. Verify one task in your own test chat before adding continuous operation and recovery.

Contacting GetTGAPI support

Visit gettgapi.com/en/help#contact and explain whether you have not obtained credentials or already have them but the program fails. Share a redacted error and version, not credentials or session files.

GetTGAPI assists with developer portal applications and existing credentials, rather than debugging every third-party program. Support can first check whether the issue belongs to the application process. See service scope.