Movatterモバイル変換


[0]ホーム

URL:


API Reference

Functions API Reference

Functions are defined similar to aRoute Handler in Next.js. When using Next.js App Router, you can define a function in a file underapp/api/my-route/route.ts in your project. Vercel will deploy any file underapp/api/ as a function.

Vercel Functions use a Web Handler, which consists of therequest parameter that is an instance of the web standardRequest API. Next.jsextends the standardRequest object with additional properties and methods.

To use a Web Handler, you must be using Node.js 18 or later. If you are using an earlier version, you must use theNode.js signature.

ParameterDescriptionNext.jsOther Frameworks
requestAn instance of theRequest objectNextRequestRequest
app/api/hello/route.ts
exportfunctionGET(request:Request) {returnnewResponse('Hello from Vercel!');}

To configure your function when using the App Router in Next.js, you usesegment options, rather than aconfig object.

app/api/example/route.ts
exportconstruntime='nodejs';exportconstmaxDuration=15;

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

PropertyTypeDescription
runtimestringThis optional property defines the runtime to use, and if not set the runtime will default tonodejs.
preferredRegionstringThis optional property and can be used to specify theregions in which your function should execute. This can only be set when theruntime is set toedge
maxDurationintThis optional property can be used to specify the maximum duration in seconds that your function can run for. This can't be set when theruntime is set toedge

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.
  • OIDC (OpenID Connect) Methods: Methods for working with OIDC, which are imported from@vercel/functions/oidc. These include:
    • awsCredentialsProvider(): This function helps in obtaining AWS credentials using Vercel's OIDC token.
    • getVercelOidcToken(): Retrieves the OIDC token from the request context or environment variable.

See the@vercel/functions documentation for more information.

Last updated on June 25, 2025

Previous
Configuring Functions
Next
@vercel/functions

Was this helpful?

supported.
On this page

[8]ページ先頭

©2009-2025 Movatter.jp