Logo

LLMs Support

Expose your documentation to Large Language Models (LLMs) with built-in text generation.


With the rise of AI tools and coding assistants, it's becoming best practice to provide LLM-friendly versions of your documentation. Docstra makes this easy with built-in utilities to generate plain-text and markdown representations of your entire documentation tree or individual pages.

This allows you to easily create llms.txt files or .mdx versions of your pages, giving LLMs the context they need to help your users.

Generating Full Documentation Text (llms.txt)

You can generate a full hierarchical text representation of your documentation using the getLLMText() method. This is perfect for serving an llms.txt file at the root of your site.

Example: Next.js App Router

Create a new route handler at app/llms.txt/route.ts:

app/llms.txt/route.ts
import { source } from '@/lib/source'; // Adjust the import path to your source file export async function GET() { const text = source.getLLMText(); return new Response(text, { headers: { 'Content-Type': 'text/plain', }, }); }

Exposing Individual Pages

You can also expose individual documentation pages as clean markdown by using the getLLMPage(slug) method. This strips away complex layout components while preserving the essential content structure.

1. Create a dynamic route

Create a route handler to serve text representations of specific pages. For example, at app/llms.mdx/[[...slug]]/route.ts:

app/llms.mdx/[[...slug]]/route.ts
import { source } from '@/lib/source'; // Adjust the import path to your source file export async function GET( request: Request, { params }: { params: { slug?: string[] } } ) { const text = source.getLLMPage(params.slug); if (!text) { return new Response('Not Found', { status: 404 }); } return new Response(text, { headers: { 'Content-Type': 'text/plain', }, }); }

2. Configure Next.js rewrites

To allow users (and LLMs) to simply append .mdx to any documentation URL, you can configure Next.js rewrites in your next.config.ts (or next.config.js):

next.config.ts
import type { NextConfig } from 'next'; import { withDocstra } from 'docstra/mdx'; const nextConfig: NextConfig = { async rewrites() { return [ { source: '/docs/:path*.mdx', destination: '/llms.mdx/:path*', }, ]; }, }; export default withDocstra(nextConfig);

Now, when an LLM requests /docs/features/search.mdx, Next.js will rewrite the request to your /llms.mdx/features/search route handler, returning the parsed, LLM-friendly markdown of that page.

How is this guide?

Last updated on April 30, 2026