Skip to content
TGWAY
Channels & Bots STEP 88 / 99

Peers and access_hash: Why an ID Alone Can't Send

Users and channels need an ID plus an access_hash in the Telegram API. Why it exists, why it differs per account, keeping a peer store and handling min info.

  • Applies toDevelopers
  • LevelL4
  • Reading time3 min
  • Verified

The short answer

  1. 1Users and channels need ID + access_hash; basic groups need only the ID.
  2. 2access_hash differs per account and only comes from API results.
  3. 3Keep a peer store, and never overwrite full info with min info.
In this article
  1. Peers: whoever you exchange messages with
  2. Why access_hash exists
  3. Keep a peer store
  4. min: partially filled information
  5. FAQ
  6. At a glance

Peers: whoever you exchange messages with

In the Telegram API, anything you send messages to or ask about, whether a user, a group or a channel, is called a peer. In the Bot API a numeric chat_id was enough (see reading chat IDs), but in the user-account API, pointing at a user or a channel needs a second value along with the ID: the access_hash.

PeerWhat you need to refer to it
UserID + access_hash
Channel or supergroupID + access_hash
Basic groupID only

Why access_hash exists

If a numeric ID were enough to message any user, someone could count upwards through the numbers and spam everyone. The access_hash is proof that this account has legitimately come across this peer. That gives it two properties:

  • It differs per account (session). An access_hash your account received cannot be used from another account, so a list of IDs and hashes obtained from someone else cannot be used to send messages.
  • You only get it from what the API returns. It comes with user and channel information included in results such as received messages, the chat list, contacts and username lookups (contacts.resolveUsername).

Keep a peer store

The official documentation recommends storing peer information (ID, access_hash, name and so on) persistently on the device. Update it every time a response includes users or channels, and take values from it when you send. That way you do not waste requests looking peers up again after every restart, and you avoid rate limits; see reading API errors.

min: partially filled information

Some user information comes only partly filled, such as users attached to a message in a large group. It is marked min, and its access_hash cannot be used as is in requests.

  • If you already have full information stored, do not overwrite it with the min version.
  • If you must refer to that peer, you can point at it as "the user seen in this message", using inputPeerUserFromMessage or inputPeerChannelFromMessage.

TDLib manages the peer store for you; see building TDLib. How group and channel types differ is in channels, supergroups and basic groups.

FAQ

What is access_hash in the Telegram API?

A value that must accompany a user or channel ID. It proves your account has legitimately seen that peer.

Can I use an access_hash from another account?

No. Each account receives its own access_hash values.

What does min mean on a Telegram user object?

The information is only partly filled and its access_hash cannot be used directly; don't overwrite full stored data with it.

Sources

Summary

At a glance

Peers and access_hash: Why an ID Alone Can't Send — at a glance illustration
  1. 1Peers

    User, channel or group you talk to.

  2. 2access_hash

    Proof your account has seen the peer; not shareable.

  3. 3Store

    Update from every response; use FromMessage peers for min info.

Share this guide

Send it to a friend who has the same question.

Telegram WhatsApp
More

Open on your phonePoint your phone camera here to open this guide.

Updated

Related articles

View all ›