How to Add llms.txt to Cloudflare Pages
Cloudflare Pages is one of the easiest hosts to serve llms.txt from — you get it at the site root with zero server config. Here are the three ways to do it, from simplest to most flexible.
Method 1: Static File (Simplest — Works for Any Framework)
Every Cloudflare Pages project serves files from a build output directory. Put an
llms.txt file there and it's automatically live at your domain root.
Astro / SvelteKit / 11ty (static dir): drop the file in the framework's static folder, which is copied to the output as-is:
# Astro: place this at public/llms.txt
# (public/ contents are copied to dist/ at build time) Plain HTML / Vite / React (manual): add llms.txt next to your
index.html in the output folder (e.g. dist/llms.txt), or configure your
build tool to copy it there.
Build and deploy as usual — either with wrangler pages deploy or via your connected Git
repository. The file is served at https://your-domain.com/llms.txt.
Method 2: Dashboard Direct Upload
If you manage the project through the Cloudflare dashboard (Workers & Pages → your project →
Upload assets), you can upload an llms.txt file directly without a
build pipeline at all. This is handy for a quick test or for sites not built from a repo.
Method 3: Pages Function (Dynamic Generation)
When your llms.txt should reflect live data — a fresh sitemap, a changing content list, or a dynamic
llms-full.txt — generate it with a
Pages Function:
// functions/llms.txt.js — serves https://your-domain.com/llms.txt
export async function onRequest() {
const llms = `# Example Site
> A concise description of the site.
## Docs
- [Getting Started](https://example.com/docs/start)`;
return new Response(llms, {
headers: { "Content-Type": "text/plain; charset=utf-8" },
});
}
The function can fetch your sitemap.xml, filter sections, or pull from a CMS — anything
you can do in JavaScript. Just keep the response under the platform's limits and serve
text/plain.
Verify It's Live
After deploying, check from the command line or browser:
curl -I https://your-domain.com/llms.txt
# Expect: HTTP/2 200, Content-Type: text/plain Then validate the content — run the URL through our free llms.txt checker to confirm the H1, absolute URLs, and Markdown structure are spec-compliant before AI engines start reading it.
Common Mistakes
- Wrong folder — the file must end up in the build output, not your source root. Check
dist/(or your output dir) after building. - Relative URLs — llms.txt links must be absolute (
https://…), not/docs/start. - Missing H1 — the file must start with a single
#heading with your site name; the blockquote summary below it is what agents read for context. - Caching surprises — static files on Pages are cached at the edge; if you regenerate via a Function, add
Cache-Control: no-store(as above) or purge when content changes.
Once it's live, add the file to your footer or homepage so human visitors (and the agents that read pages) discover it — and consider adding an llms-full.txt companion for content-heavy sections.