Skip to content

Edge Functions

Build high-performance APIs that are deployed to every Edge Network region.

Edge Functions are available in Beta on all plans

Vercel Edge Functions allow you to deliver content to your site's visitors with speed and personalization. They are deployed globally by default on Vercel's Edge Network and enable you to move server-side logic to the Edge, close to your visitor's origin.

Edge Functions use the Vercel Edge Runtime, which is built on the same high-performance V8 JavaScript and WebAssembly engine that is used by the Chrome browser. By taking advantage of this small runtime, Edge Functions can have faster cold boots and higher scalability than Serverless Functions.

Edge Functions run after the cache, and can both cache and return responses.

Edge Functions location within Vercel infrastructure.

Create your first Edge API Route using the pages/api directory in your project.

// pages/api/hello.ts

import { NextRequest, NextResponse } from 'next/server';

export default (req: NextRequest) => {
  return NextResponse.json({
    name: `Hello, from ${req.url} I'm now an Edge Function!`,

export const config = {
  runtime: 'experimental-edge',

Learn more on the Edge Functions Quickstart or view the Edge Functions API documentation.

Some of the benefits of using Edge Functions include:

  • Reduced latency: Code runs geographically close to the client. A request made in London, will be processed by the nearest edge node to London, instead of Washington, USA (us-east-1)
  • Speed and agility: Edge Functions use Edge Runtime, which, due to its smaller API surface, allows for a faster startup than Node.js
  • Personalized content: Serve personalized cached content based on attributes such as visitor location, system language, or cookies

As with all solutions, Edge Functions may not be suitable for all use cases and there are some limitations you should be aware of:

See Limitations for more information.

  • Edge Functions run after the cache, and unlike Edge Middleware, can cache responses
  • Edge Functions are similar to Serverless Functions but run on a different infrastructure:
    • Serverless Functions are run from either the default region, or a custom selected region. On every invocation, they are run from the same region regardless of where the request is coming from
    • Edge Functions are copied across the Edge Network, so on every invocation, the region closest to the request will run the function. This has the potential to dramatically reduce latency
  • Like Edge Middleware, but unlike Serverless Functions, Edge Functions use the Edge runtime. This allows for faster cold boots, but means that you cannot use Node.js APIs in Edge Functions
  • Their signature matches Edge Middleware
    • Note that when using Edge Functions with Next.js (as API Routes configured to run at the edge), you can import and use the next/server helpers (NextRequest, NextResponse). However, this is not a requirement
  • Edge Functions can return responses
  • When using Edge Functions, you can add the @vercel/edge package and import helper functions such as geolocation, rewrite, and ipAddress

Edge Functions have full support for the console API, including time, debug, timeEnd, etc. Logs will appear inside your Vercel project by clicking View Functions Logs next to the deployment.