Skip to Content

Functions API Reference

An instance of the Request object


Parameter

Deprecated, use


Description

instead


Next.js

Other Frameworks

Next.js (/app)Next.js (/pages)Other frameworks

}

Cancellation is opt-in. In your vercel.json, add "supportsCancellation": true to the specific paths you want to enable it for:

How it works
  • exportfunctionGET(request:Request) {
  • }
  • "regions": ["iad1"],
  • "functions": {

{

Cancelling requests lets you clean up resources or stop long-running tasks when the client disconnects, such as when a user stops an AI chat response or closes a browser tab.

Open in
  • TypeScript
  • When cancellation is enabled, Vercel notifies your function through the standard AbortSignal on request.signal. When the client disconnects, the signal fires and the function is terminated.
  • "supportsCancellation":true

Use the abort signal


});

signal:request.signal,

returnnewResponse(response.body, {

The request.signal is a standard AbortSignal. You can pass it directly to any API that accepts one, such as fetch:

status:response.status,

constresponse=awaitfetch('https://my-backend-service.example.com', {

});

headers:response.headers,

}

headers: { Authorization:`Bearer ${process.env.AUTH_TOKEN}` },

exportasyncfunctionGET(request:Request) {

If you need to perform custom cleanup on abort or coordinate cancellation across multiple operations, you can create your own AbortController and wire it to request.signal:

Our Services

exportasyncfunctionGET(request:Request) {

Digital Marketing

constresponse=awaitfetch('https://my-backend-service.example.com', {

constabortController=newAbortController();
});
console.log('request aborted');
abortController.abort();

headers: {

},

request.signal.addEventListener('abort', () => {
Authorization:`Bearer ${process.env.AUTH_TOKEN}`,
status:response.status,
returnnewResponse(response.body, {

});

});

}
signal:abortController.signal,
headers:response.headers,

To run cleanup work after the client disconnects, combine waitUntil with a deferred promise. This keeps the execution context alive until your cleanup finishes. In this example, abortPendingTask only runs when the client disconnects. On normal completion, the pipeTo promise resolves cleanup once all response bytes have been sent:

signal:request.signal,

import { waitUntil } from'@vercel/functions';

console.log('request aborted, cancelling pending task');

abortPendingTask().finally(cleanup.resolve);
});
waitUntil(cleanup.promise);
});

returnnewResponse(readable, {

const { readable,writable } =newTransformStream();

if (!request.signal.aborted) cleanup.resolve();
});
});
status:response.status,

headers:response.headers,

awaitfetch('https://my-backend-service.example.com/cancel', {

});
}
method:'POST',
}

exportconstmaxDuration=15;

exportconstruntime='nodejs';

The table below shows a highlight of the valid config options. For detailed information on all the config options, see the Configuring Functions docs.

TypeScript

To configure your function when using the App Router in Next.js, you use segment options, rather than a config object.

Property

Type

string

Description

This optional property defines the runtime to use, and if not set the runtime will default to nodejs. Starting in Next.js 16.3, setting runtime to edge is no longer supported.

SIGTERM signal

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.

string

int

This optional property can be used to specify the regions in which your function should execute.

This optional property can be used to specify the maximum duration in seconds that your function can run for.

process.on('SIGTERM', () => {


// Perform cleanup operations here

Your code can run for up to 500 milliseconds (30 seconds for container images) after receiving a SIGTERM signal. After this period, the function instance will be terminated immediately.

TypeScript

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.
  • getDeadline(): Returns the shared invocation deadline for the current function invocation as a Date object.
  • 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 Runtime Cache.

The @vercel/oidc package

See the @vercel/functions documentation for more information.


OIDC Helper methods

See the @vercel/oidc documentation for more information.

The @vercel/oidc-aws-credentials-provider package

getVercelOidcToken(): Retrieves the OIDC token from the request context or environment variable.

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

@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.

AWS Helper methods

awsCredentialsProvider(): This function helps in obtaining AWS credentials using Vercel's OIDC token.

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

More resources

Last updated August 11, 2026

Cross-link map: Functions API Reference (/docs/functions/functions-api-reference)From the Vercel docs graph (built 2026-09-21T05:26:59.511Z), spanning vercel.com docs + KB, nextjs.org, ai-sdk.dev, and other Vercel documentation sites. Full graph as JSON: https://vercel.com/docs/graph.jsonSemantically closest pagesVercel Functions — Build API routes, webhooks, and agent request handlers with Vercel Functions, then test and debug them with Vercel CLI.Connect to Amazon Web Services \(AWS\) — Learn how to configure your AWS account to trust Vercel's OpenID Connect \(OIDC\) Identity Provider \(IdP\).Using the Node.js Runtime with Vercel Functions — Learn how to use the Node.js runtime to create functions and deploy Node.js servers on Vercel.OpenID Connect \(OIDC\) Federation — Secure the access to your backend using OIDC Federation to enable auto-generated, short-lived, and non-persistent credenConnect to Microsoft Azure — Learn how to configure your Microsoft Azure account to trust Vercel's OpenID Connect \(OIDC\) Identity Provider \(IdP\).This page links to (16)proxy.js — API reference for the proxy.js file.route.js — API reference for the route.js special file.Route Segment Config — Learn about how to configure options for Next.js route segments.after — API Reference for the after function.NextRequest — API Reference for NextRequest.API Routes — Next.js supports API Routes, which allow you to build your API without leaving your Next.js app. Learn how it works hereRuntime Cache — Vercel Runtime Cache is a specialized cache that stores responses from data fetches in Vercel functionsConfiguring Functions — Learn how to configure the runtime, region, maximum duration, and memory for Vercel Functions.Configuring Maximum Duration for Vercel Functions — Learn how to set the maximum duration of a Vercel Function.Configuring regions for Vercel Functions — Learn how to configure regions for Vercel Functions.Configuring the Runtime for Vercel Functions — Learn how to configure the runtime for Vercel Functions.@vercel/functions API Reference \(Node.js\) — Learn about available APIs when working with Vercel Functions.vercel.functions API Reference \(Python\) — Learn about available APIs when working with Vercel Functions in Python.Static Configuration with vercel.json — Learn how to use vercel.json to configure and override the default behavior of Vercel from within your project.Global network and regions — View the list of regions supported by Vercel's CDN and learn about our global infrastructure.Streaming in web applications — Learn how streaming works in web applications. Explore benefits, use cases, and implementation details with Vercel FunctPages that link here (22)By site: ai-sdk (2) · nextjs (1) · vercel-changelog (5) · vercel-kb (3) · vercel-web (1) · workflow (1) · vercel-docs (9)From ai-sdkStopping StreamsVercel Deployment GuideFrom nextjsafter — API Reference for the after function.From vercel-changelogNode.js Vercel Functions now support fetch web handlersNode.js Vercel Functions now support per-path request cancellation Node.js Vercel Functions now support request cancellationVercel Functions now support graceful shutdownwaitUntil is now available for Vercel FunctionsFrom vercel-kbAdd structured application logs to Vercel Functions — Learn how to add structured application logs to Vercel Functions to help troubleshoot function issues in real time.How can I use geolocation IP headers? — Learn how to read geolocation headers on Vercel with Next.js or any frontend framework.Can I use SMTP with Vercel? — Vercel Functions can open SMTP connections on the Node.js runtime. Learn which ports are open, why you must await the seFrom vercel-webVercel Functions are now faster—and powered by RustFrom workflowStreaming — Stream real-time data to clients without waiting for workflow completion.From vercel-docsVercel Functions — Build API routes, webhooks, and agent request handlers with Vercel Functions, then test and debug them with Vercel CLI.Container Images — Deploy OCI container images with a Dockerfile or Containerfile on Vercel Functions.Getting started with Vercel Functions — Build your first Vercel Function in a few steps.Using the Node.js Runtime with Vercel Functions — Learn how to use the Node.js runtime to create functions and deploy Node.js servers on Vercel.Static Configuration with vercel.json — Learn how to use vercel.json to configure and override the default behavior of Vercel from within your project.Programmatic Configuration with vercel.ts — Define your Vercel configuration in vercel.ts with @vercel/config for type-safe routing and build settings.Routing Middleware API — Learn how you can use Routing Middleware, code that executes before a request is processed on a site, to provide speed aSandbox firewall — Define network policies on sandboxes, preventing data exfiltration.Firewall concepts — Understand the fundamentals behind the Vercel Firewall.