Telegram Bot API · error code

Telegram error 502: 502 Bad Gateway

RetryableHTTP 502502 / 504: Telegram-side

Last verified against Telegram Bot API reference

What Telegram returns
502 Bad Gateway (HTML body from the api.telegram.org front end; not a JSON Bot API response)

What error 502 means

A 502 from api.telegram.org means the front-end proxy in front of the Bot API could not get a valid response from the backend. Unlike every other entry on this page, the body is usually an HTML error page rather than the {"ok":false,...} JSON object, so JSON parsing in your client may throw before you even see a status code. Telegram does not document 502 as a Bot API error; it is infrastructure behaviour you should nevertheless plan for.

It is transient by nature. Short incidents lasting seconds to minutes happen occasionally, and during them every method, including getMe, can return 502. If your bot uses webhooks, inbound delivery is unaffected by an outbound 502, but any API call you make while handling the update will fail.

Your token, chat IDs and code are not the cause.

What it looks like

HTTP/1.1 502 Bad Gateway
Content-Type: text/html

<html><head><title>502 Bad Gateway</title></head>...

Why it happens

  • A brief Telegram-side incident or deploy.
  • Network path problems between your host and Telegram's edge.
  • A local Bot API server that is down or misconfigured, if you are pointing at one.

How to fix Telegram error 502

  1. 1Retry with exponential backoff and jitter (for example 1s, 2s, 4s, up to a cap), and treat 502 as retryable in your HTTP layer.
  2. 2Guard JSON parsing: check the HTTP status and Content-Type before decoding the body.
  3. 3If using webhooks, return 200 to Telegram quickly and queue outbound calls so a transient 502 does not cause update redelivery storms.
  4. 4Check whether the issue is regional by testing from another network.

How to stop it recurring

Make your API client resilient to non-JSON bodies and to 5xx statuses, with idempotent retries for sends where duplicates would be harmful (or accept rare duplicates for notifications). Keep outbound work on a durable queue so a short outage delays rather than loses messages.

Distinguish infrastructure 5xx from throttling: a 429 carries a JSON body with retry_after and must be honored exactly, while a 502 has no wait hint and standard exponential backoff applies. If 502s coincide with your webhook going quiet, check getWebhookInfo and the endpoint checklist in Telegram bot not responding before assuming a Telegram outage.

Official reference: Telegram Bot API reference. See all Telegram error codes or the Telegram limits and quotas.

Related codes

Error 502 - quick answers

What does Telegram error 502 mean?

A 502 from api.telegram.org means the front-end proxy in front of the Bot API could not get a valid response from the backend. Unlike every other entry on this page, the body is usually an HTML error page rather than the {"ok":false,...} JSON object, so JSON parsing in your client may throw before you even see a status code.

How do I fix Telegram error 502?

1. Retry with exponential backoff and jitter (for example 1s, 2s, 4s, up to a cap), and treat 502 as retryable in your HTTP layer. 2. Guard JSON parsing: check the HTTP status and Content-Type before decoding the body. 3. If using webhooks, return 200 to Telegram quickly and queue outbound calls so a transient 502 does not cause update redelivery storms. 4. Check whether the issue is regional by testing from another network.

Can I retry after error 502?

Yes - this is a retryable condition. Back off (start around one second and double on each attempt, with jitter) and watch for a retry-after hint from the platform before resending.

Stop debugging Telegram by hand

Connect the channel through Conferbot: tokens, webhooks and retries are handled, failures show as readable status.