502 Bad Gateway

A server acting as a gateway or proxy received an invalid response from the upstream server.

Status code502
Status textBad Gateway
Category5xx Server Error
Response has bodyUsually
SpecificationRFC 9110

What does 502 Bad Gateway mean?

A server acting as a gateway or proxy received an invalid response from the upstream server. It belongs to the 5xx Server Error class, which means the server failed to fulfil an apparently valid request. The problem is on the server side.

When do APIs return 502?

The application behind a load balancer or reverse proxy is down, crashed, or returned garbage.

How to fix a 502 Bad Gateway

Usually transient and infrastructure-level. Retry with backoff. If it persists, the upstream application is likely not running or is crashing on startup — check whether the origin is healthy, not whether your request is valid.

Reproduce a 502 response

The fastest way to understand a status code is to trigger one and read the full response. Open the API tester and send a request to https://httpbin.org/status/502 — you will see the 502 status along with every response header the server sent. Comparing those headers against a working request is often what reveals the cause.

When you are debugging a real endpoint, check the response headers as carefully as the body, and confirm you are using the right HTTP method for the operation.

Related 5xx status codes