Skip to content
>_VibeUnstuck

FUNCTION_INVOCATION_TIMEOUT

Last verified:

The fix

FUNCTION_INVOCATION_TIMEOUT. Log: Vercel Runtime Timeout Error: Task timed out after N seconds. Return sooner, or set maxDuration within the plan.

  1. 1

    Read the seconds in the log

    Open the function log for the route that 504'd. Task timed out after 10 seconds and Task timed out after 300 seconds are the same error with different caps. Compare that number with maxDuration on the route and with Settings, Functions, Function Max Duration. Fix an infinite loop or a missing return before you raise the number. A fetch with no deadline will burn the whole duration.

  2. 2

    Abort the slow call, and set maxDuration only if the work fits

    Give the outbound call a deadline shorter than the function limit, and return a response from the catch. In the App Router, export const maxDuration is seconds. Keep it inside the plan: 300 on Hobby, 800 on Pro or Enterprise unless that function is on the extended-duration beta. Redeploy. A larger number in the file does not raise the plan maximum. The Pages Router form is export const config = { maxDuration: 60 }.

    export const maxDuration = 60;
    
    const res = await fetch(url, {
      signal: AbortSignal.timeout(15_000),
    });
  3. 3

    Move work that cannot finish inside the plan

    A multi-minute export, a loop over every row, or a model call with no upper bound does not belong in the request the browser is waiting on. Accept the job, return a response, and finish it somewhere that is allowed to run longer. Vercel's duration docs point at Workflows for work that needs more than the plan maximum. Raising maxDuration to 800 on Hobby does not make Hobby an 800-second plan.

  4. 4

    Leave the Edge runtime if the first byte is the limit

    Vercel functions on the Edge runtime have to begin the response within 25 seconds, then they can stream for up to 300 seconds. Current Next.js marks export const runtime = 'edge' as deprecated. Remove that export and keep the Node.js runtime, which is the default, then set maxDuration inside the plan. A route that is still on Edge does not get the Node duration table by adding maxDuration alone.

Why it happens

Vercel stops a function that runs longer than its maximum duration and returns 504 FUNCTION_INVOCATION_TIMEOUT. The runtime log reads Vercel Runtime Timeout Error: Task timed out after, then the limit in seconds. That number is the cap that fired. It includes time spent streaming the response, and time spent waiting on another service.

With fluid compute, which Vercel's duration docs say is enabled by default, the Node.js, Bun, and Python limits are: Hobby, 300 seconds default and 300 seconds maximum. Pro and Enterprise, 300 seconds default and 800 seconds maximum. Above 800 seconds is a beta, up to 1800 seconds, set on that function in code or in vercel.json, not as a project default. The beta runtimes listed are nodejs22.x, nodejs24.x, nodejs26.x, Bun 1.x and 1.4.x, and Python 3.12, 3.13, and 3.14. Secure Compute and Static IPs do not support durations above 800 seconds during the beta. A log that says 10 seconds or 15 seconds means this route or this project's Function Max Duration is that number. It does not mean every plan still dies at 10.

The Edge runtime is a different rule. It has to begin sending a response within 25 seconds, and it can then stream for up to 300 seconds. A function that never returns a response waits until the limit and then times out. Streaming does not remove the cap.

The next error you'll probably hit

Once this is fixed, the usual follow-up is You exceeded your current quota. You exceeded your current quota: the OpenAI account has no credit. Add billing. Retrying will not help. Rate limit reached is the other 429.

Prompt to paste back into your AI tool

Paste this above the error.

Vercel returns 504 FUNCTION_INVOCATION_TIMEOUT. The log says: Vercel Runtime Timeout Error: Task timed out after <N> seconds. The route is <file>. The plan is <Hobby, Pro, or unknown>.

Do not set maxDuration to 800 or 1800 as a first step. Do not retry the timed-out request in a loop. Do not claim streaming removes the duration cap.

1. Say what the handler is waiting on, and whether every path returns a Response.
2. Add AbortSignal.timeout on outbound fetches, shorter than the function limit, and return an error when it fires.
3. If the work fits in the plan, set export const maxDuration to the seconds it needs. Hobby maximum is 300. Pro and Enterprise maximum is 800, unless this function is on the extended-duration beta (per function, up to 1800, listed runtimes only).
4. If the file exports runtime = 'edge', remove it. Current Next.js deprecates that export. The Edge runtime has to start its response within 25 seconds.
5. If the work cannot finish inside the plan maximum, say so and stop. Do not invent a queue API. Change only this route.

Common questions

+I exported maxDuration = 800 and it still dies at 300 seconds. Why?

Hobby's maximum is 300 seconds, and 300 is also the default on every plan when fluid compute is on. 800 is the Pro and Enterprise maximum. A higher export does not raise the plan. Redeploy after you change the route, and check Settings, Functions, Function Max Duration, because the project default can be lower than the plan maximum.

+Will streaming keep the function alive past the limit?

No. Vercel counts the time you spend sending the response. The cap applies to the whole invocation. The Edge runtime also has to start that response within 25 seconds.

+The log says Task timed out after 10 seconds. The docs say 300. Which is it?

The number in Vercel Runtime Timeout Error: Task timed out after is the limit that stopped this function. A project default or a maxDuration of 10 still wins. The 300 second figure is the fluid-compute default and the Hobby maximum, not a promise that this route was given 300.

+What is FUNCTION_INVOCATION_TIMEOUT?

The 504 Vercel returns when the function passes its duration. The runtime log for the same failure is Vercel Runtime Timeout Error: Task timed out after, then the seconds. A build that stops while installing is a different log.

Related errors