Vercel Functions
Functions enable running compute on-demand without needing to manage your own infrastructure, provision servers, or upgrade hardware.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](/_next/image?url=https%3A%2F%2Fassets.vercel.com%2Fimage%2Fupload%2Fv1706106025%2Fdocs-assets%2Fstatic%2Fdocs%2Fconcepts%2Ffunctions%2Ffunctions-overview-light.png&w=3840&q=75)
![Functions location within Vercel's managed infrastructure](/_next/image?url=https%3A%2F%2Fassets.vercel.com%2Fimage%2Fupload%2Fv1706106025%2Fdocs-assets%2Fstatic%2Fdocs%2Fconcepts%2Ffunctions%2Ffunctions-overview-dark.png&w=3840&q=75)
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): Opt for this cost-effective choice when you need lightweight JavaScript functions that execute close to the user
To learn more, see choosing a runtime.
To get started with creating your first function, copy the code below:
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.
Functions have full support for the console
API, including time
, debug
, timeEnd
, etc.
Runtime logs for all functions can be found in the Logs tab. You can use the various filters and options to find specific log information. These logs are held for an amount of time based on your plan.
When a Function on a specific path receives a user request, you may see more than one log when the application renders or regenerates the page.
This can occur in the following situations:
- When a new page is rendered
- When you are using Incremental Static Regeneration (ISR)
In the case of ISR, multiple logs are the result of:
- A stale page having to be regenerated. For stale pages, both HTML (for direct browser navigation) and JSON (for Single Page App (SPA) transitions) are rendered simultaneously to maintain consistency
- On-demand ISR happening with
fallback
set asblocking
. During on-demand ISR, the page synchronously renders (e.g., HTML) upon request, followed by a background revalidation of both HTML and JSON versions
In Next.js projects, logged functions include API Routes (those defined in pages/api/**/*.ts
or app/**/route.ts
).
Pages that use SSR, such as those that call getServerSideProps
or export revalidate
, will also be available both in the filter dropdown and the real time logs.
For more information on what to do next, we recommend the following articles:
Was this helpful?