<!-- Generated from llms-txt-sveltekit/index.html. The canonical document is the HTML page. -->

- [ Home ](/) 
/
- [ How to create ](/how-to-create/) 
/
- SvelteKit guide            
# llms.txt for SvelteKit

Three approaches: a static file in static/ (zero config), a +server.ts endpoint for dynamic generation, or a content-driven generator using import.meta.glob.

Last updated: April 22, 2026

ℹ Which approach to use?

Use the  static file  if your  llms.txt  changes rarely, it requires zero
code. Use a  +server.ts endpoint  if you generate it from your content at build time,
or need to update it without redeploying.

## Option 1: static file (recommended)

SvelteKit copies everything in the `static/` directory directly into the build output.
Place your file at `static/llms.txt` and it will be served at `/llms.txt` on
every adapter, no config changes needed.
static/llms.txt, directory structure   
Copy

```
# SvelteKit, zero-config static approach
#
# Place your file at: static/llms.txt
# SvelteKit copies everything in static/ directly into the build output.
# Your file will be served at /llms.txt on any adapter.
#
# Project structure:
# your-sveltekit-app/
# ├── static/
# │   └── llms.txt   ← add this
# ├── src/
# └── svelte.config.js
#
# No config changes needed. Deploy as normal.

```

This approach works with **adapter-static**,
**adapter-cloudflare**, **adapter-vercel**,
**adapter-node**, and every other official adapter. The file is served with the
adapter's default static file headers.

## Option 2: +server.ts endpoint

Create a server route at `src/routes/llms.txt/+server.ts` that exports a `GET` handler. SvelteKit will serve it at the path `/llms.txt`.
src/routes/llms.txt/+server.ts   
Copy

```
// src/routes/llms.txt/+server.ts
// SvelteKit server endpoint, dynamic generation
import type { RequestHandler } from './$types';

export const GET: RequestHandler = () => {
const body = `# Your Site

> One-sentence description of what your site is.

## Product

- [Overview](https://yoursite.com/product): core capabilities.
- [Pricing](https://yoursite.com/pricing): plans and limits.

## Documentation

- [Getting started](https://yoursite.com/docs): install, first steps.
- [API reference](https://yoursite.com/api): full endpoint catalog.

## Optional

- [Changelog](https://yoursite.com/changelog): version history.
`;

return new Response(body, {
headers: {
'Content-Type': 'text/plain; charset=utf-8',
'Cache-Control': 'public, max-age=3600, stale-while-revalidate=86400',
},
});
};

```

Set an appropriate `Cache-Control` header so edge CDNs cache the response, it rarely changes
and doesn't need fresh delivery on every request.

✓ Pre-rendering with adapter-static

If you're using  adapter-static  for a fully static site, add  export const prerender = true;  at the top of your
+server.ts . SvelteKit will generate  llms.txt 
as a static file at build time.
src/routes/llms.txt/+server.ts, with prerender   
Copy

```
// src/routes/llms.txt/+server.ts
// Add this line to pre-render the endpoint at build time (adapter-static / SSG)
export const prerender = true;

import type { RequestHandler } from './$types';

export const GET: RequestHandler = () => {
const body = `# Your Site\n\n> Summary.\n\n## Docs\n\n- [Guide](https://yoursite.com/docs)`;
return new Response(body, {
headers: { 'Content-Type': 'text/plain; charset=utf-8' },
});
};

```

## Option 3: generate from content

If you manage documentation or blog posts in `src/content/`, you can generate `llms.txt` automatically at build time using
`import.meta.glob`. The example below reads all Markdown files and builds the link
list from their frontmatter.
src/routes/llms.txt/+server.ts, from content   
Copy

```
// src/routes/llms.txt/+server.ts
// Generate llms.txt from your Markdown content files
import type { RequestHandler } from './$types';

// Import all Markdown files in src/content/docs/
const docs = import.meta.glob('/src/content/docs/**/*.md', { eager: true }) as Record ;

export const prerender = true;

export const GET: RequestHandler = () => {
const lines = Object.values(docs)
.filter((m) => m.metadata?.title && m.metadata?.slug)
.map((m) => `- [${m.metadata!.title}](https://yoursite.com/docs/${m.metadata!.slug}/): ${m.metadata!.summary ?? ''}`);

const body = [
'# Your Site',
'',
'> One-sentence summary.',
'',
'## Documentation',
'',
...lines,
].join('\n');

return new Response(body, {
headers: { 'Content-Type': 'text/plain; charset=utf-8' },
});
};

```

Adjust the glob pattern and metadata fields to match your project's content structure. Run the [validator](/validator/) in CI to catch broken outputs after content migrations.

## Adapter notes

- **adapter-cloudflare**, static files in `static/`
are served directly by Cloudflare Pages' global CDN with automatic caching. Server routes become
Cloudflare Pages Functions. See the [Cloudflare Pages guide](/llms-txt-cloudflare/) for
cache header recommendations and purge commands. 
- **adapter-vercel**, static files are served from Vercel's Edge Network. Server
routes run as Vercel Functions (or Edge Functions with `export const config = { runtime: 'edge' }`). See the [Vercel guide](/llms-txt-vercel/) for `vercel.json`
rewrite options. 
- **adapter-static**, all routes must be pre-renderable. Add `export const prerender = true;` to your
`+server.ts`, or use the static file approach instead. 
- **adapter-node**, server routes run as a Node.js HTTP server. The `+server.ts` approach is ideal; add aggressive
`Cache-Control` headers so a reverse proxy (nginx, Caddy) can cache the response.   
## Verify

After deploying, confirm the file is served correctly:
Verification   
Copy

```
curl -I https://yoursite.com/llms.txt
# Expected:
# HTTP/2 200
# content-type: text/plain; charset=utf-8

curl https://yoursite.com/llms.txt | head -5
# Should print the first lines of your file
```

Then paste the URL into the [validator](/validator/) for a full spec-compliance check.

## Related guides

- [How to create llms.txt](/how-to-create/), templates and checklist. 
- [Cloudflare Pages guide](/llms-txt-cloudflare/), SvelteKit + adapter-cloudflare
specifics. 
- [Vercel guide](/llms-txt-vercel/), SvelteKit + adapter-vercel specifics. 
- [Best practices](/best-practices/), what to include and what to leave out. 
- [Validator](/validator/) · [Generator](/generator/).        
## Sources

- [ llmstxt.org, official spec ](https://llmstxt.org/)
- [ SvelteKit docs, routing ](https://svelte.dev/docs/kit/routing)
- [ SvelteKit docs, server routes ](https://svelte.dev/docs/kit/routing#server)           
On this page

- [ Option 1: static file (recommended) ](#static)
- [ Option 2: +server.ts endpoint ](#server)
- [ Option 3: generate from content ](#dynamic)
- [ Adapter notes ](#adapters)
- [ Verify ](#verify)
