# How to stop Vercel Functions from timing out

**Author:** Vercel

---

[Vercel Functions](https://vercel.com/docs/functions) can time out from long-running tasks, inefficient code, or upstream service issues. The good news is that most timeouts trace back to a small set of causes, and the single most effective fix is the same in almost every case.

Here’s how to work through it, starting with that fix and ending with the edge cases that survive it.

## Why do Vercel Functions time out?

Before touching or changing anything, it helps to know what you're fighting.

A Vercel Function times out for one of three reasons:

- It runs longer than its configured duration
  
- Its own code is inefficient
  
- An upstream service it depends on is slow or unresponsive
  

Long-running tasks and network-bound work are the usual culprits, and the same change often solves both.

That change is [Fluid Compute](https://vercel.com/blog/introducing-fluid-compute).

## What is Fluid Compute?

Fluid Compute is Vercel’s next-generation compute model that bridges the gap between traditional dedicated servers and serverless architecture. It handles multiple concurrent requests within a single function instance rather than starting a new instance for every individual request.

The best way to avoid hitting limits is to use [Fluid Compute](https://vercel.com/docs/functions/fluid-compute), which blends serverless flexibility with server-like capabilities, including the ability to run functions for up to 5 minutes on free plans and up to roughly 13 minutes on paid plans.

### How does Fluid Compute fix function timeouts?

Fluid Compute is a hybrid solution that removes many of the traditional limitations of serverless functions in four ways:

- **Optimized concurrency:** Multiple function invocations can run on a single instance, reducing cold starts and improving resource utilization.
  
- **Extended durations:** Enjoy longer maximum durations (up to 800 seconds on Pro and Enterprise) without additional configurations.
  
- **Dynamic scaling and automatic cold start optimizations:** Scale seamlessly during traffic spikes and benefit from bytecode caching to reduce cold starts.
  
- **Background processing:** Use [`waitUntil`](https://vercel.com/docs/functions/functions-api-reference/vercel-functions-package#waituntil) (or [`after`](https://nextjs.org/docs/app/api-reference/functions/after) with Next.js) to continue tasks after sending an initial response.
  

If you frequently encounter timeouts or want to run network-intensive tasks, enabling Fluid Compute is your most effective long-term solution. Turning it on takes only a few clicks.

## How to enable Fluid Compute

Once you’ve decided to use it, enabling Fluid Compute is a quick dashboard change:

- Open your project in the [Vercel dashboard](https://vercel.com/dashboard)
  
- Click on Settings and select the Functions section
  
- Scroll to the Fluid Compute section and enable the toggle for Fluid Compute
  
- Click Save to apply your changes
  
- Redeploy your project for the changes to take effect
  

After you redeploy, the change takes effect across your functions. Fluid Compute is available on [Node.js](https://vercel.com/docs/functions/runtimes/node-js), [Python](https://vercel.com/docs/functions/runtimes/python), [Edge](https://vercel.com/docs/functions/runtimes/edge), [Bun](https://vercel.com/docs/functions/runtimes/bun), [Go](https://vercel.com/docs/functions/runtimes/go), [Wasm](https://vercel.com/docs/functions/runtimes/wasm), [Ruby](https://vercel.com/docs/functions/runtimes/ruby), and [Rust](https://vercel.com/docs/functions/runtimes/rust) runtimes, with optimized concurrency on Node.js and Python.

## 4 more causes of function timeouts and how to troubleshoot

If you’re still encountering timeouts even after enabling Fluid Compute, the cause is usually in your function’s own logic or its dependencies.

Work through these four common causes in order.

### 1\. The function is taking too long

Start with how long your calls take.

Here are two things to check:

- **Check API or database call durations:** If these calls exceed your configured timeout, you’ll see timeouts.
  
- **Extend your function’s duration if needed:** You can override Fluid Compute defaults for even longer-running functions setting `maxDuration` in the route segment config (up to 800 seconds on Pro and Enterprise):
  

`export const maxDuration = 800;`

If you’re building AI applications, we recommend [streaming](https://vercel.com/docs/functions/streaming-functions), so the response starts returning before the full computation finishes.

### 2\. No response is being returned

A function that never responds will always hit the ceiling. Always send an HTTP response, even an error. If your function never returns anything, Vercel will wait until the maximum duration has elapsed and then time out.

Make sure every code path ends in a response, including your error branches.

### 3\. Infinite loops

Unintended long-running functions are often loops that never exit. Inspect your logic for any loops or recursive calls that never terminate. This is a common cause of unintended long-running functions, and you can confirm it by inspecting your function [runtime logs](https://vercel.com/docs/runtime-logs) and [observability](https://vercel.com/docs/observability).

If the logs show a function running right up to the limit with no output, a non-terminating loop is the likely cause.

### 4\. Upstream errors

Finally, look outside your own code at the services it depends on.

The fix is graceful handling. Verify third-party integrations or database connections. If upstream services fail to respond, handle the error gracefully and return a response, such as an error message, rather than waiting indefinitely.

Catching upstream failures and returning early keeps a slow dependency from consuming your full duration budget.

## Next steps

[Create a new Vercel project](https://vercel.com/new) with Fluid Compute enabled, or [start from a template](https://vercel.com/templates) and deploy in minutes.

## Related resources

- [Vercel Functions](https://vercel.com/docs/functions)
  
- [Fluid Compute](https://vercel.com/docs/functions/fluid-compute)
  
- [Configuring function duration](https://vercel.com/docs/functions/configuring-functions/duration)
  
- [Streaming functions](https://vercel.com/docs/functions/streaming-functions)
  
- [Runtime logs](https://vercel.com/docs/runtime-logs)

---

[View full KB sitemap](/kb/sitemap.md)
