A Vercel 504 gateway timeout with the code FUNCTION_INVOCATION_TIMEOUT means one function invocation ran longer than its allowed duration. With Fluid Compute that limit defaults to 300 seconds, so the question is what the function spent them on: a slow model or API call, a heavy query, a loop, or a handler that never sent its response.
Vercel 504 gateway timeout: what the error code tells you
A Vercel 504 gateway timeout names the clock that ran out in its error code. FUNCTION_INVOCATION_TIMEOUT means a function passed its duration limit; EDGE_FUNCTION_INVOCATION_TIMEOUT and MIDDLEWARE_INVOCATION_TIMEOUT are the Edge and middleware versions; two more 504 codes sit in the group Vercel lists as internal.
Vercel returns that function code as a 504 Gateway Timeout when a function exceeds its duration budget, and Vercel’s FUNCTION_INVOCATION_TIMEOUT page names three possible causes: an error within the function itself, a slow network call, or an issue with the environment the function runs in. The platform’s deadline is the last line of defense. The app’s own deadlines come before it, and they are one of the ten reliability checks for an AI-built app.
If the page in front of you only says an error occurred with your deployment, open the response or the logs: the code there, a function invocation timeout or one of its relatives, tells you which clock to look at. Vercel’s list of error codes has five codes with the 504 status, and the table adds two strings that turn up in logs and old error pages.
| What you see | Where you see it | What it confirms | Whose side | First check |
|---|---|---|---|---|
FUNCTION_INVOCATION_TIMEOUT | The 504 response and the function’s logs | A function invocation took longer than the allowed execution time | Your function or a service it calls | The request’s log lines, and the last one before the cut |
EDGE_FUNCTION_INVOCATION_TIMEOUT | The 504 response from a function on the Edge runtime | An Edge Function took longer than the allowed execution time; Vercel Edge Functions must begin a response within 25 seconds | Your Edge code or what it waits on | Whether the first byte leaves inside 25 seconds |
MIDDLEWARE_INVOCATION_TIMEOUT | The 504 response from Routing Middleware | The middleware took too long or sent no response chunk for a while | Your middleware or a backend it waits on | Stream the backend’s response, as Vercel’s page recommends |
Vercel Runtime Timeout Error: Task timed out after 300 seconds | Runtime logs; posts on Vercel’s community forum show the same line with 10 or 15 seconds; not stated in Vercel’s docs | The task hit a 300-second budget, the Fluid Compute default | Your function or a service it calls | A smaller number in the line means a legacy limit or a maxDuration someone set |
This Serverless Function has timed out. | An error page, posted with a 504 and FUNCTION_INVOCATION_TIMEOUT on Vercel’s community forum; not stated in Vercel’s docs | The same function timeout | Your function or a service it calls | The same as the first row |
INTERNAL_FUNCTION_INVOCATION_TIMEOUT or INTERNAL_EDGE_FUNCTION_INVOCATION_TIMEOUT | Listed by Vercel under its platform errors, type Internal | A function or Edge Function took longer than the allowed execution time | Either: Vercel says platform errors can come from your deployment or your use of platform features | Vercel’s status page, then the same checks as the first two rows |
A spinner that keeps turning after the gateway timeout is a second problem in the page itself: the frontend never handled the failed response, so it needs an error state of its own.
Why a Vercel function timeout happens
A Vercel function timeout happens when the work inside one request outlasts the function’s limit. Vercel’s error page lists slow API or database requests, a missing response, an infinite loop and upstream errors as things to check, and names an unhandled exception as a common cause. With AI features, the slow request includes the model call.
Older answers call it the Vercel serverless function timeout; the setting is the same, and so is the order of fixes further down. A Vercel timeout comes from one clock per invocation, and the table maps each cause to what you would notice and the control that prevents it.
| Cause, after Vercel’s error page | What you see | The control that prevents it |
|---|---|---|
| Slow API or database requests | The route hangs on one call | A deadline on every external call, and a faster query |
| The function is taking too long to process a request | Exports, bulk email or a chain of model calls fail once real data arrives | A background job that is safe to repeat |
| The function isn’t returning a response | Every request to that route times out, even tiny ones | A response on every code path, errors included |
| An infinite loop, upstream errors or an unhandled exception | CPU stays busy, or an error is swallowed and the request waits | Error handling that reports the failure |
Across the 21 third-party apps we audited in June and July 2026, the Reliability & Correctness pillar averages 31.4 out of 100, the lowest of the twelve pillars, with every one of the 21 scored on it. Those apps are a selected set, not a random sample, so the figure describes that group and says nothing about AI-built apps as a whole.
When the timeouts come from AI generation or exports running inside requests and a launch, an investor review or a client handover is close, start with a free audit: a video call with nothing to prepare, where we weigh up with you whether each slow route needs a deadline, a stream or a background job. In the Production Hardening Sprint, our engineers set deliberate timeouts for AI, email, payment and other external calls and move long-running AI generation, exports and bulk communication into background jobs.
A model or API call with no deadline of its own
A model call that answers quickly in a demo can take far longer with a long prompt or a busy provider. A call with no deadline of its own waits until the function’s limit cuts it, so the visitor gets a 504 instead of a message the app chose. The AI SDK accepts a timeout option and an abortSignal on its calls, and the AI SDK’s note on timeouts on Vercel covers streamed answers cut off by the function’s duration. The model client keeps clocks of its own as well, and the OpenAI client’s own timeout and retries all run inside the same request.
Work that is longer than any request should be
A report, a batch of embeddings, an agent running several model calls in a row: none of this has an upper bound that a request can promise. Handing the work to waitUntil does not escape the clock. Vercel’s functions reference says promises passed to waitUntil() will have the same timeout as the function itself, and are canceled if the function times out. The fix for this kind of work is the background job in the fixes below.
A query that was fast with test data
A query over a handful of test rows answers at once; the same query over a real table may not. The function waits on the database like any outside call, so a slow query spends the same duration budget as a slow API. A missing index and an N+1 loop are two reasons why a Supabase query slows down as the table grows, and both are worth ruling out first. A route that works on a laptop and fails after deploy is also the general case of an app that works locally but fails live, where environment variables and network rules differ too.
A handler that never sends its response
Vercel’s error page states the rule plainly: the function must return an HTTP response, even if that response is an error, and if no response is returned, the function will time out. In generated code, we’d look first for three shapes: an error branch with no return, a promise nobody awaits, and a stream that is never closed. A route that should answer in milliseconds and still times out on every request points here first.
What is the maximum timeout for Vercel functions? The limits by plan
The maximum timeout for Vercel functions on Fluid Compute is 300 seconds on Hobby and 800 seconds on Pro and Enterprise, where a beta allows up to 1,800 seconds per function on supported Node.js, Bun and Python runtimes. Every plan’s default is 300 seconds.
| Plan | Default | Standard maximum | Extended maximum (beta) |
|---|---|---|---|
| Hobby | 300 seconds | 300 seconds | None listed |
| Pro | 300 seconds | 800 seconds | 1,800 seconds, set per function |
| Enterprise | 300 seconds | 800 seconds | 1,800 seconds, set per function |
Limits checked on October 20, 2026, against Vercel’s duration limits, for projects with Fluid Compute switched on.
The Vercel timeout limit is a wall clock, and Vercel’s max duration counts the whole invocation: for request handlers it includes time spent processing the request and sending the response, including streamed responses. On Hobby, 300 seconds is both the default and the ceiling, so no setting raises it.
New projects have run on Fluid Compute by default since April 23, 2025, and older projects can switch it on. A project with it switched off runs on the older limits, and those are not stated in Vercel’s docs today. If you have seen 10-second or 60-second limits quoted, those numbers date from earlier: a May 2024 changelog let Hobby functions run up to 60 seconds instead of 10. So open the project’s Settings, then Functions, and look at the Fluid Compute switch before trusting any number you read.
Edge runtime functions follow a different rule: they must begin sending a response within 25 seconds and can keep streaming data for up to 300 seconds. Prices are a separate question, set out in what each Vercel plan costs. A build that never finishes runs on another clock entirely, the one behind a Vercel build stuck on Queued.
How to fix the timeout, in order
Find the call first, then fix it where it starts; raising the limit comes late because it only moves the wall. The settings and code below are taken from the documentation of Vercel, Next.js, the AI SDK and MDN, and were not run for this page.
Find the call that used the time
Start in the browser. In the Vercel dashboard, open Observability, then the Vercel Functions tab, and sort by duration to find your slowest routes; the External APIs tab shows latency for all external API calls your functions make, and sorting it by P75 latency finds the slowest upstream services. From a terminal, vercel logs --environment production --query "timeout" --since 1h --expand pulls the last hour’s timeout lines, as Vercel’s guide to slow functions shows. The error page also points to each deployment’s own log view at the /_logs path of its URL. Then log the start and end of each database query, model call and third-party request with the elapsed milliseconds, and compare the slowest with your plan’s limit.
Give every outside call its own deadline
A deadline the app sets fails on the app’s terms: a clear error the page can show, a log line with the dependency’s name, and a retry only where repeating is safe. With fetch, pass AbortSignal.timeout() and catch the error by name; MDN documents that the signal aborts with a TimeoutError DOMException on timeout.
try {
const res = await fetch(url, { signal: AbortSignal.timeout(5000) });
return Response.json(await res.json());
} catch (err) {
if (err instanceof DOMException && err.name === 'TimeoutError') return Response.json({ error: 'The provider is slow. Try again.' }, { status: 503 });
throw err;
}
For the AI SDK, the same deadline is its timeout option in milliseconds or an abortSignal, and the call is aborted if it takes longer than that. We’d set each deadline well under the function’s limit, so the route still has time to answer the person waiting. Payment, email and auth SDKs and the database driver need the same treatment, which is set out under a timeout on every external call.
Stream the answer, knowing it does not stop the clock
When a person is waiting for generated text, streaming shows the first words early, which is what an AI chat route needs. The AI SDK’s streamText returns a result with helpers such as toUIMessageStreamResponse and toTextStreamResponse that send it as a streamed response. Streaming does not buy extra time: Vercel Functions limits count the sending of a streamed response inside the same duration, as the limits section above sets out. On the Edge runtime the first byte also has the 25-second rule from that section.
How to increase the Vercel timeout with maxDuration, and when not to
Vercel’s maxDuration setting is how many seconds one function may run, up to the plan’s maximum. A Next.js App Router route exports it from the route file; older Next.js versions and some other frameworks and runtimes set it per path in vercel.json. It fixes work with a known upper bound, not a call that has no deadline.
A Vercel timeout increase is one line of config. In a Next.js App Router route file, the export looks like this, with 60 as an example value inside every plan’s maximum; the Next.js route segment config lists the option with its default “Set by deployment platform”, and Next.js added it in v13.4.10.
export const maxDuration = 60;
export async function POST(request: Request) {
// ...
}
The Pages Router and Node.js /api routes export a config object instead, export const config = { maxDuration: 60 }. Other frameworks and runtimes, and Next.js versions older than 13.5, set it per function path in vercel.json:
{
"functions": {
"api/generate.js": {
"maxDuration": 60
}
}
}
In a Next.js project that uses the src directory, prefix the path with /src/ so Vercel detects the function. The project default lives in the dashboard: Settings, then Functions, then the Default Max Duration field in the Function Max Duration section. During the beta, anything above 800 seconds has to be set for each function in code or in vercel.json; project-level defaults above 800 seconds are not supported yet. The time not to reach for it: a call with no upper bound meets any number you pick, and on Hobby there is no higher number to pick.
Move the long work into a background job
A background job is the fix for work longer than any request: the route saves a job record and answers at once, a worker outside the request runs the work, and the page reads the job’s status. The job must be safe to run twice and must keep a record when it fails.
For Vercel long-running tasks, such as a monthly report, a bulk email or a chain of model calls, the pattern has four parts:
- The route saves a job and returns its id straight away.
- A worker picks the job up and runs it outside the request.
- The page polls or subscribes for the job’s status.
- The job is safe to run twice, and a failed run leaves a record.
The one Vercel timeout workaround that removes the request limit instead of moving it is to stop doing the work inside the request. Vercel’s own option is Vercel Workflows, which run multi-step logic as durable code that can retry failed steps and resume across crashes and deployments; the duration page describes them as letting code pause, resume and maintain state without duration limits. A worker on another host is the other route. The jobs table, the claim query and where the worker runs on each host are under moving long tasks into the background, which also answers where else the work can live. Running a job twice without doing it twice, and keeping the failures somewhere a person can act on them, takes an idempotency key and a failed-jobs table.
How to verify each fix
A timeout fix is verified by causing the slow case on purpose. A dependency slowed past its deadline must fail fast with a clear message, a job run past the request window must finish with its status visible, and a job replayed after its retries run out must leave one result and a failure record.
Run these on a staging deployment you own, never on production, and keep the evidence each one names.
- 01 Slow one dependency on purpose: point it at a staging test endpoint that sleeps past your deadline. Pass: the route fails in about the deadline with the app's own message, not a gateway timeout. Keep the log line with the elapsed time.
- 02 Send the largest real input the route accepts. Pass: its duration stays well under the function's limit. Keep the duration, the input and the date.
- 03 Test a job past the request limit: start a job that runs longer than any request could. Pass: the job finishes and the page shows its status the whole way. Keep the job record.
- 04 Replay a job, then make it fail until its retries run out. Pass: one result, plus a failed-job record someone can act on. Keep both records.
- 05 After the release, filter the logs for the timeout codes from the first table over the next days of real traffic. Pass: none on the fixed routes. Keep the filtered log view.
In the Production Hardening Sprint, checks 1, 3 and 4 are how three deliverables are verified: 6.4 by simulating a slow dependency and confirming bounded waits and a useful failure state, 6.6 by running a long task beyond the normal request window and verifying completion and user-visible status, and 6.7 by replaying jobs, exhausting retries and verifying one intended result plus a recoverable failure record.
Who can help when the timeouts keep coming back
Doing it yourself fits when one route times out and the code is readable: the steps above are the whole job. A freelancer fits when the fix is one known change, such as a deadline on a call or a streamed route. An agency fits when new features are part of the same work. A fixed-scope service like ours fits when the timeouts are one symptom among several production gaps before a launch.
Our Production Hardening Sprint sets deliberate timeouts for external calls and moves long-running work into background jobs. Hosting, paid tools and API usage are paid through your accounts, so a Pro plan or a worker host stays a cost on your own bill.
Common questions about 504 errors on Vercel
Is 504 gateway timeout my fault?
Not on the visitor’s side: when the code is a function, Edge or middleware timeout, the function or a service it calls ran past its limit, whatever the visitor’s browser or network is doing. The two internal timeout codes are platform errors, yet Vercel’s pages for them list the same checks on the function’s code, so look at Vercel’s status page at vercel-status.com and then at the function.
Is a 504 error permanent?
No. A 504 lasts as long as its cause: a slow provider can recover by itself, while a call that always runs longer than the function’s limit fails on every request until the code or the limit changes.
How can I fix a 504 gateway timeout error?
Find the call that held the request open, then give it a deadline, make it faster or move it into a background job. Raise the duration limit with maxDuration only for work with a known upper bound, up to 300 seconds on Hobby and 800 seconds on Pro and Enterprise with Fluid Compute.
When should I get help with Vercel functions that keep timing out?
Get help when the same routes time out again after the limit was raised, or when the fix means building background jobs nobody on the team has built before. AxonBuild can go over the routes that keep failing with you on a free audit, a video call that needs no code access.
Requests timing out once your app is live?
A timeout in production usually means a slow call is sitting inside the request, and raising the limit only hides it for a while. On the audit, we talk through which actions time out with you and your team and name the likely causes. Then you know whether to speed up the work or move it off the request.
Book a free audit →
Free · 30 minutes · No code access needed