Menu

Functions API Reference

Last updated November 8, 2025

Vercel Functions use a Web Handler, which consists of the request parameter that is an instance of the web standard Request API. Next.js extends the standard Request object with additional properties and methods.

ParameterDescriptionNext.jsOther Frameworks
requestAn instance of the Request objectNextRequestRequest
context Deprecated, use @vercel/functions insteadN/A{ waitUntil }
api/hello.ts
export function GET(request: Request) {
  return new Response('Hello from Vercel!');
}
api/hello.js
export function GET(request) {
  return new Response('Hello from Vercel!');
}
app/api/hello/route.ts
export function GET(request: Request) {
  return new Response('Hello from Vercel!');
}
app/api/hello/route.js
export function GET(request) {
  return new Response('Hello from Vercel!');
}
This feature is only available in the Node.js runtime.

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

  1. In your vercel.json file, add "supportsCancellation": true to the specific paths you want to opt-in to cancellation for your functions. For example, to enable everything, use **/* as the glob or app/**/* for app router:

    vercel.json
    {
      "regions": ["iad1"],
      "functions": {
        "api/*": {
          "supportsCancellation": true
        }
      }
    }

    When you have enabled cancellation, anything that must be completed in the event of request cancellation should be put in a waitUntil or after promise. If you don't, there is no guarantee that code will be executed after the request is cancelled.

  2. Use the AbortController 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:

    api/abort-controller/route.ts
    export async function GET(request: Request) {
      const abortController = new AbortController();
     
      request.signal.addEventListener('abort', () => {
        console.log('request aborted');
        abortController.abort();
      });
     
      const response = await fetch('https://my-backend-service.example.com', {
        headers: {
          Authorization: `Bearer ${process.env.AUTH_TOKEN}`,
        },
        signal: abortController.signal,
      });
     
      return new Response(response.body, {
        status: response.status,
        headers: response.headers,
      });
    }
This feature is supported on the Node.js and Python runtimes.

A SIGTERM 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 SIGTERM signal. After this period, the function instance will be terminated immediately.

api/hello.ts
process.on('SIGTERM', () => {
  // Perform cleanup operations here
});
api/hello.js
process.on('SIGTERM', () => {
  // Perform cleanup operations here
});

The @vercel/functions package provides a set of helper methods and utilities for working with Vercel Functions.

  • waitUntil(): 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.
  • getEnv: This function retrieves System Environment Variables exposed by Vercel.
  • geolocation(): Returns location information for the incoming request, including details like city, country, and coordinates.
  • ipAddress(): Extracts the IP address of the request from the headers.
  • invalidateByTag(): Marks a cache tag as stale, causing cache entries associated with that tag to be revalidated in the background on the next request.
  • dangerouslyDeleteByTag(): Marks a cache tag as deleted, causing cache entries associated with that tag to be revalidated in the foreground on the next request.
  • invalidateBySrcImage(): 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.
  • dangerouslyDeleteBySrcImage(): 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.
  • getCache(): Obtain a RuntimeCache object to interact with the Vercel Data Cache.

See the @vercel/functions documentation for more information.

The @vercel/oidc package was previously provided by @vercel/functions/oidc.

The @vercel/oidc package provides helper methods and utilities for working with OpenID Connect (OIDC) tokens.

See the @vercel/oidc documentation for more information.

The @vercel/oidc-aws-credentials-provider package was previously provided by @vercel/functions/oidc.

The @vercel/oidc-aws-credentials-provider package provides helper methods and utilities for working with OpenID Connect (OIDC) tokens and AWS credentials.

See the @vercel/oidc-aws-credentials-provider documentation for more information.


Was this helpful?

supported.