Functions API Reference
Vercel Functions use a Web Handler, which consists of the parameter that is an instance of the web standard API. Next.js extends the standard object with additional properties and methods.
Cancelling requests is useful for cleaning up resources or stopping long-running tasks when the client aborts the request — for example, when a user hits stop on an AI chat or they close a browser tab.
To cancel requests in Vercel Functions
-
In your file, add to the specific paths you want to opt-in to cancellation for your functions. For example, to enable everything, use as the glob or for app router:
When you have enabled cancellation, anything that must be completed in the event of request cancellation should be put in a or promise. If you don't, there is no guarantee that code will be executed after the request is cancelled.
-
Use the API in your function to cancel the request. This will allow you to clean up resources or stop long-running tasks when the client aborts the request:
A signal is sent to a function when it is about to be terminated, such as during scale-down events. This allows you to perform any necessary cleanup operations before the function instance is terminated.
Your code can run for up to 500 milliseconds after receiving a signal. After this period, the function instance will be terminated immediately.
The package provides a set of helper methods and utilities for working with Vercel Functions.
- : This method allows you to extend the lifetime of a request handler for the duration of a given Promise . It's useful for tasks that can be performed after the response is sent, such as logging or updating a cache.
- : This function retrieves System Environment Variables exposed by Vercel.
- : Returns location information for the incoming request, including details like city, country, and coordinates.
- : Extracts the IP address of the request from the headers.
- : Marks a cache tag as stale, causing cache entries associated with that tag to be revalidated in the background on the next request.
- : Marks a cache tag as deleted, causing cache entries associated with that tag to be revalidated in the foreground on the next request.
- : Marks all cached content associated with a source image as stale, causing those cache entries to be revalidated in the background on the next request. This invalidates all cached transformations of the source image.
- : Marks all cached content associated with a source image as deleted, causing those cache entries to be revalidated in the foreground on the next request. Use this method with caution because deleting the cache can cause many concurrent requests to the origin leading to cache stampede problem.
- : Obtain a object to interact with the Vercel Data Cache.
See the documentation for more information.
The package was previously provided by .
The package provides helper methods and utilities for working with OpenID Connect (OIDC) tokens.
See the documentation for more information.
The package was previously provided by .
The package provides helper methods and utilities for working with OpenID Connect (OIDC) tokens and AWS credentials.
Was this helpful?