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/504504 vs similar status codes
502 means the upstream answered with an invalid response or refused the connection. 504 means the upstream never answered in time.
499 means the client gave up waiting and closed the connection; 504 means the proxy gave up waiting for the upstream.
Frequently Asked Questions
What does HTTP Status 504 mean?
Why am I getting a 504 status code?
How do I fix a 504 Gateway Timeout error?
What is the difference between 504 Gateway Timeout and 502 Bad Gateway?
What is the difference between 504 Gateway Timeout and 499 Client Closed Request?
How can I test how my app handles a 504 response?
Other 5xx status codes
Browse the full HTTP status codes directory or troubleshoot terminal errors in the Error Fix Encyclopedia.