GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Docs
  • AI Gateway
  • AI SDK
  • Sandbox
  • Container Registry
  • Workflow
  • Vercel Agent
  • v0↗
  • Vercel MCP
  • AI Integrations
  • Deployments
  • CLI
  • Functions
  • Delivery Network

This view

  • Original page
  • New address

GeezerVison is showing vercel.com — Vercel Functions

 

On this page

  • Build APIs and agent request handlers
  • Run work after a response
  • Create your first Vercel Function
  • How the Vercel Functions lifecycle works
  • Why functions should run near your data source
  • Viewing Vercel Function metrics
  • How Vercel Functions pricing works
  • Explore Vercel Functions
  • Related guides
 

Run server-side code with Vercel Functions

Build API routes, webhooks, and agent request handlers that scale with traffic. Test locally and trace deployed requests with Vercel CLI.
Create a functionDebug slow functions
api/hello.ts
export default {
  fetch(request: Request) {
    return new Response('Hello from Vercel!');
  },
};
app/api/chat/route.ts
import { streamText } from 'ai';
 
export async function POST(request: Request) {
  const { prompt } = await request.json();
  const result = streamText({
    model: 'openai/gpt-5.6-sol',
    prompt,
  });
 
  return result.toTextStreamResponse();
}
api/hello.ts
import { waitUntil } from '@vercel/functions';
 
async function getProducts() {
  const response = await fetch('https://api.vercel.app/products');
  return response.json();
}
 
export default {
  fetch() {
    waitUntil(getProducts().then((json) => console.log({ json })));
    return new Response('Accepted', { status: 202 });
  },
};

When you deploy your application, Vercel automatically sets up the tools and optimizations for your chosen framework. It ensures low latency by routing traffic through Vercel's CDN, and placing your functions in a specific region when you need more control over data locality.

Functions location within Vercel's managed infrastructureFunctions location within Vercel's managed infrastructure
Functions location within Vercel's managed infrastructure

Build APIs and agent request handlers

Vercel Functions run request-driven API routes, webhooks, streamed model responses, and agent turns. Use Vercel Workflows or eve when an agent must preserve progress across pauses or deployments.

  • Zero server management. Deploy code that scales automatically with traffic
  • Fluid compute. Reduced cold starts, lower latency, and lower costs via optimized concurrency
  • Multi-runtime support. Use Node.js, Python, Go, and more
  • Regional control. Pin functions to a region close to your data source
  • Framework-aware. Vercel detects and optimizes for your framework automatically
  • Built-in observability. View invocations, errors, and cost metrics in the dashboard

Run work after a response

Use waitUntil for short tasks that continue after you send a response, within the function's maximum duration. For work that needs retries, durable waits, or a continuous worker, compare the background worker options. Follow Running background workers on Vercel for detailed examples.

Create your first Vercel Function

Copy the code below to create your first function:

api/hello.ts
export default {
  fetch(request: Request) {
    return new Response('Hello from Vercel!');
  },
};

While using fetch is the recommended way to create a Vercel Function, you can still use HTTP methods like GET and POST.

app/api/hello/route.ts
export function GET(request: Request) {
  return new Response('Hello from Vercel!');
}
Open inOpen in v0

To learn more, see the quickstart or deploy a template.

How the Vercel Functions lifecycle works

Vercel Functions handle each incoming request as a new invocation, scaling automatically so you don't need to manage servers. They run in a single region by default, although you can configure them to run in multiple regions if you have globally replicated data. These functions let you add extra capabilities to your application, such as handling authentication, streaming data, or querying databases.

When a user sends a request to your site, Vercel can automatically run a function based on your application code. You don't need to manage servers or handle scaling.

Vercel creates a new function invocation for each incoming request. If another request arrives soon after the previous one, Vercel reuses the same function instance to optimize performance and cost efficiency. Over time, Vercel only keeps as many active functions as needed to handle your traffic. Vercel scales your functions down to zero when there are no incoming requests.

By allowing concurrent execution within the same instance (and so using idle time for compute), fluid compute reduces cold starts, lowers latency, and saves on compute costs. It also prevents the need to spin up multiple isolated instances when tasks spend most of their time waiting for external operations.

Why functions should run near your data source

Functions should always execute close to where your data source is to reduce latency. By default, functions using the Node.js runtime execute in Washington, D.C., USA (iad1), a common location for external data sources. You can set a new region through your project's settings on Vercel.

Viewing Vercel Function metrics

You can view various performance and cost efficiency metrics using Vercel Observability:

  1. Choose your project from the dashboard.
  2. Click on the Observability tab and select the Vercel Functions section.
  3. Click on the chevron icon to expand and see all charts.

You'll see current function usage metrics, including Active CPU, Provisioned Memory, Invocations, and savings from the optimized concurrency model when fluid compute is enabled.

How Vercel Functions pricing works

Vercel Functions are priced based on active CPU, provisioned memory, and invocations. See the fluid compute pricing documentation for more information.

If your project is not using fluid compute, see the legacy pricing documentation for Vercel Functions.

Explore Vercel Functions

What is compute?

Understand how compute works on Vercel's platform.

Fluid compute

Learn how fluid compute reduces cold starts and lowers cost.

Runtimes

Choose between Node.js, Python, Go, and other runtimes.

Configuring functions

Set regions, memory, timeouts, and other function options.

Streaming

Stream responses to deliver content as it's generated.

Limits

Review function limits including duration, payload size, and memory.

Functions logs

Inspect runtime logs for a deployment.

Debugging slow functions

Diagnose and fix functions that take too long to respond.

You and your coding agent can search the Knowledge Base for Vercel Functions guides with vercel kb search, without logging in:

terminal
npx vercel@latest kb search "Vercel Functions"

Related guides

  • Deploy a Go backend on Vercel with AI Gateway: Build and deploy a Go HTTP server that calls AI Gateway using the standard library, with no SDK dependencies.
  • Optimize Runtime Cache on Vercel: Diagnose rising Runtime Cache usage, trace reads to tags and code paths, and reduce avoidable reads while checking write cost and origin traffic.
  • How to choose between Functions, containers, and Daemons on Vercel: Choose Vercel Functions for HTTP requests, container images for custom runtimes, and Daemons for continuous background workers.
  • Migrate a Python API from Railway to Vercel: Move a FastAPI, Flask, or Django API from Railway to Vercel Functions. Replace railway.json start commands, volumes, Celery workers, and cron services.

Previous
Build AI apps / Agent Resources
Next
Getting Started

Was this helpful?

supported.
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.