Vercel FUNCTION_INVOCATION_TIMEOUT (504 Gateway Timeout)
Vercel returns FUNCTION_INVOCATION_TIMEOUT (504) when a function runs longer than its allowed duration. Common causes are slow upstream calls, a code path that never returns a response, infinite loops, or unhandled exceptions.
Cause: The function exceeds its maximum duration or never sends a response.
How to fix it
- Check the function logs for the slow or hanging call.
- Make sure every code path returns a response, including errors.
- Add timeouts to external API/database calls.
- If work is legitimately long, raise the max duration within your plan or move it to background processing.
Example
Illustrative example, not from a customer project.
export async function POST(req) {
try { ... } catch (e) {
+ return Response.json({ error: 'failed' }, { status: 500 })
}
FAQ
Is this a Vercel outage?
Usually not; it's the function exceeding its time limit.
Can I just increase the limit?
Within plan limits, yes, but fix hangs first.
Get a $149 diagnosis See pricing Launching soon? The Launch Path gets you ready for $1,195 flat.
- Fixed, or we keep working free until it is (within the written scope).
- A human reviews every fix before it ships.
- read-only access; fixes arrive as pull requests you merge
- Your $149 diagnosis is credited in full toward any paid job.