Error fixes / Vercel

Vercel

Vercel: FUNCTION_INVOCATION_TIMEOUT

A serverless function ran longer than the plan allows and Vercel stopped it.

The error

FUNCTION_INVOCATION_TIMEOUT

What it means

Vercel documents FUNCTION_INVOCATION_TIMEOUT when a function does not finish in time. On a generated app the usual causes are an API route that waits on a slow third party, a loop that never ends, or a server action that does a large amount of work the user could have queued. The visitor sees a 504. Raising the timeout without finding the slow call only delays the same failure.

Fix

  1. Open the function log for that deployment and find the route in the timeout line.
  2. See what it waits on. A missing index, an unbounded fetch, or a retry loop are the usual finds.
  3. Return a response before doing work that can wait, or move that work out of the request. Do not hold the request open while an agent polls.
  4. Add a timeout to outbound fetch calls so one stalled provider cannot consume the whole limit.
  5. Only then look at the route's max duration, and keep it within what the Vercel plan actually allows.

Prompt

Fix prompt
Paste into Cursor or Claude Code
A Vercel route fails with FUNCTION_INVOCATION_TIMEOUT.

Find the slow route from the logs. Remove unbounded loops and add a timeout around outbound fetch. Do not raise the function duration as the first change. If the work is not needed to answer the user, move it out of the request and return a normal response. Explain the call that was slow and the change you made.

Questions

Is this the same as a build failure?

No. The deployment built and the function started. It then ran too long while handling a request. Check runtime logs, not the compile log.

Will a higher maxDuration fix it?

Only if the work is legitimately long and your plan allows it. If a fetch can hang, a higher limit still times out. Cap the outbound call first.

Why is it fine locally?

next dev does not enforce the same function limit, and your laptop is often closer to the database. Run the route against the production URL.

Related fixes

Source: Vercel docs: FUNCTION_INVOCATION_TIMEOUT. Updated 14 October 2026.