llms.txt with Vercel
Three approaches: static file in public/ (zero config), Next.js App Router Route Handler, or a Vercel Edge Function for maximum flexibility.
Last updated:
Approach 1 — Static file in public/
The simplest and most reliable option. Vercel serves every file in your framework’s static assets directory directly from their global Edge Network. No code changes, no configuration, no runtime cost.
# Place llms.txt in your project's static assets directory.
#
# Framework → file location
# Next.js → public/llms.txt
# Astro → public/llms.txt
# SvelteKit → static/llms.txt
# Nuxt → public/llms.txt
# Remix → public/llms.txt
# Hugo → static/llms.txt
# Vercel serves it at /llms.txt from their global Edge Network.
# No config changes needed. After deploy, verify:
curl -I https://your-domain.com/llms.txt
# Expected: HTTP/2 200 | Content-Type: text/plain | x-vercel-cache: HIT When to use this: your llms.txt content is relatively stable and you
update it manually or via a build script. This is the right default for the vast majority of sites.
Approach 2 — Next.js App Router Route Handler
If you’re using Next.js on Vercel, the cleanest dynamic approach is an App Router Route
Handler at app/llms.txt/route.ts. With
export const dynamic = 'force-static', Vercel pre-renders it at build
time and caches the output at the edge — effectively identical to serving a static file,
but generated from your data.
// app/llms.txt/route.ts (Next.js App Router)
// Vercel detects this as a static export when dynamic = 'force-static'
// and caches the output at the edge on first request.
export const dynamic = 'force-static';
export async function GET() {
const content = [
'# My Site',
'',
'> One-sentence description of what this site is about.',
'',
'## Documentation',
'',
'- [Getting started](https://yoursite.com/docs/getting-started/): first steps.',
'- [API reference](https://yoursite.com/docs/api/): full endpoint catalog.',
'',
'## Optional',
'',
'- [Changelog](https://yoursite.com/changelog/): version history.',
].join('\n');
return new Response(content, {
headers: {
'Content-Type': 'text/plain; charset=utf-8',
'Cache-Control': 'public, max-age=3600, stale-while-revalidate=86400',
},
});
}
Remove force-static if you need truly dynamic content fetched on every request (e.g.
from a live CMS). In that case, Vercel will still cache the response at the edge based on your Cache-Control header.
For a full Next.js guide including Pages Router and llms-full.txt generation, see the
dedicated Next.js page.
Approach 3 — Vercel Edge Function
For non-Next.js projects that need dynamic generation, use a Vercel Edge Function combined with
a vercel.json rewrite to map /llms.txt to the function:
// api/llms.txt.ts — Vercel Edge Function
// Place this file in the /api directory.
// Vercel routes requests to /api/llms.txt by default,
// so use a vercel.json rewrite to map /llms.txt → /api/llms.txt
import type { VercelRequest, VercelResponse } from '@vercel/node';
export const config = {
runtime: 'edge', // Runs on Vercel's Edge Network
};
export default function handler(req: Request): Response {
const content = [
'# My Site',
'',
'> One-sentence description.',
'',
'## Core pages',
'',
'- [Getting started](https://yoursite.com/docs/getting-started/): first steps.',
].join('\n');
return new Response(content, {
headers: {
'Content-Type': 'text/plain; charset=utf-8',
'Cache-Control': 'public, max-age=3600, s-maxage=86400',
},
});
}
// vercel.json — rewrite /llms.txt to your Edge Function or API Route
// Only needed if you're not using Next.js App Router (which handles routing natively)
{
"rewrites": [
{ "source": "/llms.txt", "destination": "/api/llms" }
]
}
Edge Functions run on Vercel’s global Edge Network with near-zero cold start time.
They’re ideal for generating llms.txt from a KV store or external API without a
full server.
Cache-Control and Edge Network behaviour
For static files in public/, Vercel sets cache headers automatically. For Route
Handlers and Edge Functions, set Cache-Control explicitly:
-
public, max-age=3600, stale-while-revalidate=86400— recommended for manually-curated files. -
public, s-maxage=86400, stale-while-revalidate=604800— aggressive edge caching, good for stable content. -
public, max-age=0, s-maxage=300— 5-minute edge cache for CMS-driven content.
Vercel automatically purges the CDN cache on every new deployment, so you don’t need to
manually invalidate after pushing an updated llms.txt.
Verify after deploy
# Check headers — look for Content-Type and x-vercel-cache
curl -I https://yoursite.com/llms.txt
# Inspect content
curl https://yoursite.com/llms.txt
# Force-revalidate after a new deploy (Vercel auto-purges on deploy)
# For manual purge via Vercel REST API:
curl -X POST "https://api.vercel.com/v1/projects/{PROJECT_ID}/purge" \
-H "Authorization: Bearer {VERCEL_TOKEN}"
After verifying headers, paste your live URL into the validator
to confirm spec compliance: exactly one H1, valid link syntax (- [title](https://...)), all URLs absolute, no empty sections.
→ Full creation guide · Cloudflare Pages guide · Next.js guide