Error library

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

  1. Check the function logs for the slow or hanging call.
  2. Make sure every code path returns a response, including errors.
  3. Add timeouts to external API/database calls.
  4. 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.

$149Get a $149 diagnosis