← All errors · VercelServerless & Edge Function errors

FUNCTION_INVOCATION_TIMEOUT (504)

Exact error

504: GATEWAY_TIMEOUT. Code: FUNCTION_INVOCATION_TIMEOUT

What it means

A serverless function ran longer than its allowed maximum duration and was stopped.

Likely causes

How to fix it

  1. Find the slow call in the function logs (Vercel dashboard → Logs).

  2. Raise the limit for a route within your plan's allowed maximum. With Fluid compute (on by default for new projects), the default and the Hobby maximum are 300 seconds, and Pro and Enterprise can go up to 800 seconds. Older projects without Fluid compute have lower limits, so check Settings → Functions. In the App Router, export maxDuration from the route file; in the Pages Router or plain /api routes, export it in a config object:

    // app/api/generate/route.ts
    export const maxDuration = 120; // seconds
    
    // pages/api/generate.js
    export const config = { maxDuration: 120 };
  3. Add timeouts to outbound fetches so they fail fast:

    await fetch(url, { signal: AbortSignal.timeout(10000) });
  4. Move long jobs to a background queue/cron, or stream the response.

Still stuck after trying this? Get it fixed for $49, or you don't pay.

Prevent this next time

Guide: catch outages before your users do.

Tools that help:

Some links on this page are affiliate links: if you sign up or buy through them, FixStack may earn a commission at no extra cost to you. Learn more.

FAQ

What does "FUNCTION_INVOCATION_TIMEOUT (504)" mean?

A serverless function ran longer than its allowed maximum duration and was stopped.

What usually causes it?

Slow external API or database queries. Awaiting a promise that never resolves. Doing long jobs (AI generation, scraping, big imports) inside a single request.

How do I fix it?

1. Find the slow call in the function logs (Vercel dashboard → Logs). 2. Raise the limit for a route within your plan's allowed maximum. With Fluid compute (on by default for new projects), the default and the Hobby maximum are 300 seconds, and Pro and Enterprise can go up to 800 seconds. Older projects without Fluid compute have lower limits, so check Settings → Functions. In the App Router, export maxDuration from the route file; in the Pages Router or plain /api routes, export it in a config object: 3. Add timeouts to outbound fetches so they fail fast: 4. Move long jobs to a background queue/cron, or stream the response.

Last checked against official docs on . Sources: Vercel docs: FUNCTION_INVOCATION_TIMEOUT, Vercel docs: configuring maximum duration.

Related errors

More Vercel errors and fixes →

Tools that help

  • Railway: Deploy backends and databases; new users get $20 credit.

Some links on this page are affiliate links: if you sign up or buy through them, FixStack may earn a commission at no extra cost to you. Learn more.

Get new fixes weekly

No spam. Unsubscribe anytime. Privacy