Skip to content
TGWAY
Channels & Bots STEP 86 / 99

Expired File References: FILE_REFERENCE_EXPIRED

File references in the Telegram API expire by design. Refetch the message, profile, sticker set or story the file came from, and store its origin in advance.

  • Applies toDevelopers
  • LevelL4
  • Reading time3 min
  • Verified

The short answer

  1. 1File references have a limited lifetime; the expiry error is part of the normal flow.
  2. 2Refetch the message, profile, sticker set or story the file came from.
  3. 3Store each file's current reference and its origin.
In this article
  1. What a file reference is
  2. The errors you get when it expires
  3. Where to fetch it again
  4. Store data so you are ready for it
  5. FAQ
  6. At a glance

What a file reference is

In the Telegram API, information about a photo or document comes with a byte value called a file reference (file_reference) as well as the file's ID. To download the file you must present this reference. References have a limited lifetime, so a request with one you stored long ago is refused. The point is that file information you saw once cannot be used forever.

The errors you get when it expires

ErrorMeaning
FILE_REFERENCE_EXPIREDThe reference's lifetime is over
FILE_REFERENCE_INVALID and similarThe reference does not match; handle it the same way, with a fresh one

This error is not a bug; it is part of the normal flow. Fetch again the place where the file originally appeared, take the new reference from it, and repeat the same request.

Where to fetch it again

Where the file came fromHow to get a fresh reference
A message in a chatFetch that message again: messages.getMessages for ordinary chats, channels.getMessages for channels
A user's profile photoFetch that user's photo list again
A stickerFetch that sticker set again
A wallpaper or themeFetch that wallpaper or theme again
A storyFetch that story again

Store data so you are ready for it

The official documentation advises apps that keep files around for a long time to store two things:

  1. File ID → current reference: replace it every time a new reference arrives.
  2. File ID → where the file came from (which message in which chat, for example): when the error comes, look here and fetch the original place again.

With both stored, an expired reference can be renewed automatically and the download continues without the user noticing anything.

The rules for downloading in parts are in uploading and downloading files, and other errors in reading API errors.

FAQ

What causes FILE_REFERENCE_EXPIRED?

The file reference you sent is too old. References expire by design.

How do I get a new file reference?

Fetch the original source again, such as the message with messages.getMessages or channels.getMessages, and use the reference it contains.

Does the Bot API have file reference errors?

No. Bot API file_id values are a separate system that a bot can reuse.

Sources

Summary

At a glance

Expired File References: FILE_REFERENCE_EXPIRED — at a glance illustration
  1. 1Why

    References stop old file information being used forever.

  2. 2Fix

    Refetch the original place, take the new reference, retry.

  3. 3Prepare

    Keep file ID → reference and file ID → origin.

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 ›