Vercel Functions

Functions enable running compute on-demand without needing to manage your own infrastructure, provision servers, or upgrade hardware.
Table of Contents

Functions are available on all plans

Vercel Functions enable server-side code execution on Vercel's Managed Infrastructure, removing the need for server management or resource provisioning. These functions scale automatically with user demand and can interact with APIs, databases, and other resources as part of your project's deployment.

When deployed, Vercel's Framework defined infrastructure, automatically sets up the necessary environment, tools, and patterns as required by your chosen framework. This ensures optimal configuration for your functions, whether they run on the edge for reduced latency or in a specific region.

Vercel Functions can be written with, or without, a framework, and handle tasks such as:

  • Streaming data: Process data in real-time, such as chat messages, AI data, or financial transactions
  • Authentication: Implement authentication and authorization logic
  • Data Processing: Manage intensive tasks, such as image/video manipulation, without impeding client-side performance
Functions location within Vercel's managed infrastructure
Functions location within Vercel's managed infrastructure

The infrastructure and abilities of your Vercel Function is determined by the runtime you choose:

  • Node.js runtime (Serverless Functions): Gives you access to all the Node.js APIs that you would expect for writing on the web, with the ability to configure machine resources and dependencies.
  • Edge runtime (Edge Functions): Executes your code at the edge, close to the user. Uses a limited set of Node.js APIs.
  • Python runtime: Enables you to write your functions using Python, including Django and Flask.
  • Go runtime: Enables you to write your functions using Go, exposing a single HTTP handler from a .go file within an /api directory at your project's root.
  • Ruby runtime: Enables you to write your functions using Ruby, exposing a single HTTP handler from a .rb file within an /api directory at your project's root.

To learn more, see choosing a runtime.

To get started with creating your first function, copy the code below:

app/api/hello/route.ts
export const dynamic = 'force-dynamic'; // static by default, unless reading the request
 
export function GET(request: Request) {
  return new Response(`Hello from ${process.env.VERCEL_REGION}`);
}

To learn more, see the quickstart or deploy a template from the options below:

To learn more about the limitations for Vercel Functions, see the Runtimes reference. This highlights common limits such as size, memory, concurrency, payload size limit, duration, and pricing.

To learn more about logs for your Vercel Functions, see the Functions Logs documentation.

For more information on what to do next, we recommend the following articles:

Last updated on October 3, 2024