/ llmtxt.info

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:

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
# 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
// 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.

src/routes/llms.txt/+server.ts — with prerender
// 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
// 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<
  string,
  { metadata?: { title?: string; summary?: string; slug?: string } }
>;

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 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 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 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
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 for a full spec-compliance check.

Related guides

Sources