Ways to extend the timeout duration for Vercel Serverless functions

I've encountered an issue with my API endpoint on a NextJS project where it exceeds the 60-second time limit to execute. Despite being on a pro Vercel plan, I have been unable to extend the timeout limit successfully.

Within the endpoint itself, I attempted to modify the settings using:

export const maxDuration = 300
export const dynamic = 'force-dynamic'

However, this change did not yield the desired results. I also experimented with adding a vercel.json file at the root level (above /src) like this:

{
    "functions": {
        "pages/api/**": {
            "memory": 3008,
            "maxDuration": 300
        },
    }
}

Despite these efforts, the problem persists. I have carefully reviewed the documentation (primarily referenced here) and various discussions (like this one), but none have provided a solution.

The current setup includes NextJs version 13.5.6, confirmed pro plan status, and Node v18. I'm struggling to identify the error in my approach. Any suggestions or guidance would be greatly appreciated.

Answer №1

Your implementation appears to be a combination of the Pages Router approach and the App Router method. Consider following this example to ensure consistency:

Using Pages Router (

/pages/api/my-function/handler.ts
):

export const config = {
  maxDuration: 5, // 5 seconds
};

export default function handler(
  request: NextApiRequest,
  response: NextApiResponse,
) {
  response.status(200).json({});
}

Using App Router (/app/api/my-function/route.ts):

export const maxDuration = 5; // 5 seconds
export const dynamic = 'force-dynamic';

export function GET(request: Request) {
  return new Response('{}', { status: 200 });
}

To adjust the maximum duration of a function project-wide on Vercel using the App Router, modify the vercel.json file:

{
  "functions": {
    "app/api/**/*": {
      "maxDuration": 5
    }
  }
}

For more information on these configurations, refer to the official documentation.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What is the best way to use JavaScript to fill in missing images with alternative HTML content?

As a provider of a service that helps users find the location of pictures, I face a challenge due to the fact that the pictures are stored on another internal site. Some users may not have access to this site as my service offers additional information. Th ...

Arranging items by their total sum of arrays in React.js

I'm working with data.js where I have stored my JSON information. Here's a snippet: [ { name: 'Adam Doe', city: 'New York', mark: [8,10,10,10] }, { name: 'Catlyn Stronk', ...

NextJS's conversion of HTML to image is malfunctioning, resulting in the download of the identical reference

Having encountered difficulties with the html-to-image library while working on a Next.js project, I used the following code to convert images: import Image from "next/image"; import {toPng} from 'html-to-image' const divReferenceA = u ...

Guide to dynamically rendering Material-UI dialogs based on certain conditions

Trying to implement a dialog box based on data returned from an Apollo hook, where I need to verify that one value matches an ID. If checker === true, the dialog should open automatically and close when the user clicks the Close button. const DialogComp ...

The undead browser refuses to display a window upon attempting to open using the open function

tools first attempt Darwin 14.3.0 Darwin Kernel Version 14.3.0 io.js v1.8.1 zombie Version 4.0.7 released on April 10, 2015 second attempt Linux ubuntuG5 3.13.0-48-powerpc64-smp node.js v0.10.38 zombie Version 3.1.0 released on March 15, 2015 comman ...

TS2345: The argument provided, which is of type 'Event', cannot be assigned to the parameter expected, which is of type 'HtmlInputEvent'

I am facing an issue while trying to upload a file, and I could use some assistance in resolving it. Angular-----Error: src/app/admin/producto/create-producto-dialog.html:38:47 - error TS2345: Argument of type 'Event' is not assignable to parame ...

Javascript continues to conceal my web background without my permission

After loading my webpage, I click on a link and the expected javascript runs as planned. However, once it completes and presents the results, the page goes blank to a white screen displaying only the outcomes. My goal is to have these results showcased o ...

The mongoose library requires JSON input, yet it is unable to generate a dynamic JSON object from a Node

This question delves more into javascript and JSON concepts rather than focusing on the mongoose library. When working with Mongoose, conditions are expected to be in JSON format, like so: { $or: [ { "doc_no" : /first/i }, { "doc_type" : /second/i } ] ...

What is the best way to identify the specific row and column that was clicked within a jQuery datatable

Scenario: When a user clicks on a cell in a datatable, a specific action should be triggered based on the row and column of that cell. How can I ensure that the user does not click on a certain column? If they do not click on that column, then I want to r ...

Using the method window.open() will launch a new window instead of opening a new tab

When the page loads, I am using JavaScript to call window.open. window.open(url, "Test Page"); Initially, it opens a new Chrome window and displays the page. However, when I use the same JavaScript code after the page has loaded, it opens the page in a n ...

Preventing the $_POST action value from being altered to match the ajax page path

My current setup involves using php, jquery, and ajax to update a particular section. The ajax call is executed successfully, but I encounter an issue where the global $_SERVER[SCRIPT_NAME] changes to match the ajax path when the requested data is returned ...

Modifying the .textcontent attribute to showcase an image using JavaScript

I am working on a website and I want to change editButton.textContent = 'Edit'; so that it displays an image instead of text. var editButton = document.createElement('button'); editButton.textContent = 'Edit'; After exploring ...

next.js not receiving the necessary environmental variables for injection

import dotenv from 'dotenv'; dotenv.config(); export const getGoogleUrl = (from: string) => { const clientId: string = process.env.GOOGLE_CLIENT_ID!; const callback: string = 'http://localhost:3000/api/auth/callback/google'; c ...

The res.sendFile() function quickly delivers a 204 no content response

Currently, I am facing an issue with using Express' sendFile() function to send an image. The function does not seem to read my file at all and instead returns a 204 no-content response. Below is the code for my function/endpoint: @httpGet('/pri ...

Guide on sending JSON data to a server and receiving JSON/XML in response with JSP

I am new to developing web applications. I have successfully created a dynamic web project using Java EE on a Glassfish server. Now, I am trying to enable clients to send data to the server using JSON and receive data from the server in either JSON or XML ...

Embedded URL in dynamically created AJAX text

I created a search field that uses ajax/jquery to generate a list of users. Result: <li class="list-group-item"> <span class="glyphicon glyphicon-user"></span> <span class="badge addUserToGroup" data-user="{{ user.getId }}"&g ...

Using React to retrieve an object from a helper method through a GET request

I am in the process of turning a frequently used function in my application into a helper method that can be imported wherever it is needed. However, I am facing an issue where I am not getting a response from the function when calling it. I need to figure ...

Automatically populate email fields with pre-filled form data

Looking to create an HTML form that utilizes JS/jQuery (no PHP) to capture data from "subject" and "message" fields and send an email. The goal is for the client-side code to open the user's mail client, pre-fill the subject and body with form data, a ...

interactive division element

I'm facing an issue with making my div tag clickable in a five-star rating system. The stars are supposed to represent different values from 1 to 5. Even though the image changes on mouseover, clicking the div tag does not yield any result. This is ...

React useState Error: Exceeded maximum re-renders. React enforces a limit on the number of renders to avoid getting stuck in an endless loop

Can someone help me troubleshoot the 'Too many re-renders' error I'm encountering? I've implemented the try, catch method along with React hooks like useState and setState. My goal is to fetch data from an API and display it on a ...