llms.txt Cloudflare Workers and Pages Setup Guide
Cloudflare Workers and Pages can serve /llms.txt directly from the edge with sub-20ms global latency. Whether you upload a static file with custom _headers or return Markdown from a Worker fetch handler, proper UTF-8 and Cache-Control headers ensure AI tools always read a fresh copy.
Serve llms.txt From Cloudflare Workers or Pages
For static sites on Cloudflare Pages or Workers Static Assets, generate your file in the llms.txt Studio, drop it in public/llms.txt and pair it with a _headers rule. For dynamic sites backed by KV or D1, return it from your Worker fetch() handler with an explicit edge cache header.
const LLMS_TXT = `# My Cloudflare Site
> Fast edge APIs and developer documentation.
## Documentation
- [Getting Started](https://example.com/docs): Setup and authentication
- [API Reference](https://example.com/api): Endpoints and rate limits
`;
export default {
async fetch(request: Request): Promise<Response> {
const url = new URL(request.url);
if (url.pathname === '/llms.txt') {
return new Response(LLMS_TXT, {
headers: {
'Content-Type': 'text/plain; charset=utf-8',
'Cache-Control': 'public, max-age=3600, s-maxage=86400',
},
});
}
return new Response('Not Found', { status: 404 });
},
};/llms.txt
Content-Type: text/plain; charset=utf-8
Cache-Control: public, max-age=3600, s-maxage=86400
/llms-full.txt
Content-Type: text/plain; charset=utf-8
Cache-Control: public, max-age=3600, s-maxage=86400Check Cloudflare Bot and WAF Rules
- Test with plain
curl -I https://yourdomain.com/llms.txt— confirm you receiveHTTP 200andcontent-type: text/plain; charset=utf-8rather than a JavaScript challenge page. - Exempt
/llms.txtin custom WAF rules — if you challenge non-browser user agents site-wide, add a skip rule for exact path/llms.txtso coding assistants can fetch it cleanly. - Keep cache TTL reasonable —
max-age=3600(1 hour) balances edge speed with fast updates after documentation releases.
Cloudflare llms.txt Questions
Does Cloudflare Automatically Serve public/llms.txt With UTF-8?
Cloudflare serves .txt files as text/plain, but adding an explicit _headers rule guarantees charset=utf-8 and your preferred Cache-Control duration across all edge PoPs.
Can I Pair Cloudflare Workers AI With llms.txt?
Yes. Many teams serve a static /llms.txt index on Workers Static Assets while calling Cloudflare Workers AI (10,000 free daily Neurons) for docs Q&A or summarization.