| name | vercel-edge-functions |
| description | Build and deploy Vercel Edge Functions for ultra-low latency at the edge.
Use when creating API routes with minimal latency, geolocation-based routing,
A/B testing, or authentication at the edge.
Trigger with phrases like "vercel edge function", "vercel edge runtime",
"deploy edge function", "vercel middleware", "@vercel/edge".
|
| allowed-tools | Read, Write, Edit, Bash(vercel:*), Bash(npm:*), Grep |
| version | 1.18.0 |
| license | MIT |
| author | Jeremy Longshore <jeremy@intentsolutions.io> |
| tags | ["saas","vercel","edge","serverless","performance"] |
| compatibility | Designed for Claude Code, also compatible with Codex and OpenClaw |
Vercel Edge Functions
Overview
Edge Functions run on Vercel's Edge Network (V8 isolates) close to the user with no cold starts. They use Web Standard APIs (Request, Response, fetch) instead of Node.js APIs. Ideal for authentication, A/B testing, geolocation routing, and low-latency API responses.
Prerequisites
- Completed
vercel-install-auth setup
- Familiarity with Web APIs (Request/Response)
- Node.js 18+ for local development
Instructions
Step 1: Create an Edge Function
export const config = { runtime: 'edge' };
export default function handler(request: Request): Response {
return new Response(
JSON.stringify({
message: 'Hello from the Edge!',
region: request.headers.get('x-vercel-ip-city') ?? 'unknown',
timestamp: Date.now(),
}),
{
status: 200,
headers: { 'Content-Type': 'application/json' },
}
);
}
Step 2: Edge Function with Geolocation
Vercel injects geolocation headers into every edge request:
export config = { : };
(): {
city = request..() ?? ;
country = request..() ?? ;
region = request..() ?? ;
latitude = request..();
longitude = request..();
.({
: (city),
country,
region,
: latitude && longitude ? { : latitude, : longitude } : ,
});
}