Skip to main content
HTTP/5xx (Server Error)

504 Gateway Timeout

The server, while acting as a gateway or proxy, did not receive a timely response from an upstream server.

❓ Why does this happen?

Slow database query, unoptimized backend processing, or third-party API call hanging.

✅ How to fix it

Optimize database queries, increase proxy timeout thresholds, or make heavy tasks asynchronous.

Return or handle 504 in your stack

// app/api/resource/route.ts
export function GET() {
  return Response.json(
    { error: "Gateway Timeout", status: 504 },
    {
      status: 504
    }
  );
}

Live 504 mock endpoint

Point your app, tests, or retry logic at this free public URL to reproduce a real 504 response (CORS enabled, optional ?delay=ms up to 5000).

https://castov.com/api/mock/504

504 vs similar status codes

Frequently Asked Questions

What does HTTP Status 504 mean?
The server, while acting as a gateway or proxy, did not receive a timely response from an upstream server.
Why am I getting a 504 status code?
Slow database query, unoptimized backend processing, or third-party API call hanging.
How do I fix a 504 Gateway Timeout error?
Optimize database queries, increase proxy timeout thresholds, or make heavy tasks asynchronous.
What is the difference between 504 Gateway Timeout and 502 Bad Gateway?
502 means the upstream answered with an invalid response or refused the connection. 504 means the upstream never answered in time.
What is the difference between 504 Gateway Timeout and 499 Client Closed Request?
499 means the client gave up waiting and closed the connection; 504 means the proxy gave up waiting for the upstream.
How can I test how my app handles a 504 response?
Send a request to https://castov.com/api/mock/504 — it returns a real 504 Gateway Timeout response with CORS enabled. Add ?delay=2000 to simulate a slow server.

Other 5xx status codes

Browse the full HTTP status codes directory or troubleshoot terminal errors in the Error Fix Encyclopedia.