Recipes
Edge RuntimePatterns
Deploy serverless functions at the edge with zero cold starts. Route users to the nearest region, stream responses, and keep latency under 50ms worldwide.
Geo-aware routing
Read the x-vercel-ip-country header to serve localized content or redirect users to the nearest replica.
export const runtime = 'edge';
export async function GET(req: Request) {
const country = req.headers.get('x-vercel-ip-country');
const locale = country === 'DE' ? 'de' : 'en';
return Response.json({ locale });
}Streaming responses
Use the Web Streams API to progressively send chunks. Perfect for AI completions or real-time dashboards.
const encoder = new TextEncoder();
const stream = new ReadableStream({
start(controller) {
controller.enqueue(encoder.encode('chunk-1\n'));
controller.enqueue(encoder.encode('chunk-2\n'));
controller.close();
},
});
return new Response(stream);Know your limits
- Max 4 MB request body
- No raw TCP or filesystem access
- Execution capped at 30 s (hobby) / 60 s (pro)