Nuxt LLMs automatically generates llms.txt
markdown documentation for your Nuxt application. It provides runtime hooks to collect data from various sources (CMS, Nuxt Content, etc.) and generate structured documentation in a text-based format.
- Generates & prerenders
/llms.txt
automatically - Generate & prerenders
/llms_full.txt
when enabled - Customizable sections directly from your
nuxt.config.ts
- Integrates with Nuxt modules and your application via the runtime hooks system
- Install the module:
npm i nuxt-llms
- Register
nuxt-llms
in yournuxt.config.ts
:
export default defineNuxtConfig({
modules: ['nuxt-llms']
})
- Configure your application details:
export default defineNuxtConfig({
modules: ['nuxt-llms'],
llms: {
domain: 'https://example.com',
title: 'My Application',
description: 'My Application Description',
sections: [
{
title: 'Section 1',
description: 'Section 1 Description',
links: [
{
title: 'Link 1',
description: 'Link 1 Description',
href: '/link-1',
},
{
title: 'Link 2',
description: 'Link 2 Description',
href: '/link-2',
},
],
},
],
},
})
That's it! You can visit /llms.txt
to see the generated documentation ✨
domain
(required): The domain of the applicationtitle
: The title of the application, will be displayed at the top of the documentationdescription
: The description of the application, will be displayed at the top of the documentation right after the titlesections
: The sections of the documentation. Section are consisted of a title, one or more paragraphs of description and possibly a list of links. Each section is an object with the following properties:title
(required): The title of the sectiondescription
: The description of the sectionlinks
: The links of the sectiontitle
(required): The title of the linkdescription
: The description of the linkhref
(required): The href of the link
notes
: The notes of the documentation. Notes are a special section which always appears at the end of the documentation. Notes are useful to add any information about the application or documentation itself.full
: Thellms_full.txt
configuration. Setting this option will enable thellms_full.txt
route.title
: The title of the llms_full documentationdescription
: The description of the llms_full documentation
The module generates two different documentation formats:
The /llms.txt
route generates a concise, structured documentation that follows the llms.txt specification. This format is optimized for both human readability and AI consumption. It includes:
- Application title and description
- Organized sections with titles and descriptions
- Links with titles, descriptions, and URLs
- Optional notes section
The /llms_full.txt
route provides a more detailed, free-form documentation format. This is useful to reduce crawler traffic on your application and provide a more detailed documentation to your users and LLMs.
By default module does not generate the llms_full.txt
route, you need to enable it by setting full.title
and full.description
in your nuxt.config.ts
.
export default defineNuxtConfig({
llms: {
domain: 'https://example.com',
title: 'My Application',
full: {
title: 'Full Documentation',
description: 'Full documentation of the application',
},
},
})
The module provides a hooks system that allows you to dynamically extend both documentation formats. There are two main hooks:
This hook is called for every request to /llms.txt
. Use this hook to modify the structured documentation, It allows you to add sections, links, and metadata.
Parameters:
event
: H3Event - The current request eventoptions
: ModuleOptions - The module options that you can modify to add sections, links, etc.
This hook is called for every request to /llms_full.txt
. It allows you to add custom content sections in any format.
Parameters:
event
: H3Event - The current request eventoptions
: ModuleOptions - The module options that you can modify to add sections, links, etc.contents
: string[] - Array of content sections you can add to or modify
Create a server plugin in your server/plugins
directory:
// server/plugins/llms.ts
export default defineNitroPlugin((nitroApp) => {
// Method 1: Using the hooks directly
nitroApp.hooks.hook('llms:generate', (event, options) => {
// Add a new section to llms.txt
options.sections.push({
title: 'API Documentation',
description: 'REST API endpoints and usage',
links: [
{
title: 'Authentication',
description: 'API authentication methods',
href: `${options.domain}/api/auth`
}
]
})
})
// Method 2: Using the helper function
nitroApp.hooks.hook('llms:generate:full', (event, options, contents) => {
// Add detailed documentation to llms_full.txt
contents.push(`## API Authentication
### Bearer Token
To authenticate API requests, include a Bearer token in the Authorization header:
\`\`\`
Authorization: Bearer <your-token>
\`\`\`
### API Keys
For server-to-server communication, use API keys:
\`\`\`
X-API-Key: <your-api-key>
\`\`\`
`)
})
})
If you're developing a Nuxt module that needs to extend the LLMs documentation:
- Create a server plugin in your module:
// module/runtime/server/plugins/my-module-llms.ts
export default defineNitroPlugin((nitroApp) => {
nitroApp.hooks.hook('llms:generate', (event, options) => {
options.sections.push({
title: 'My Module',
description: 'Documentation for my module features',
links: [/* ... */]
})
})
})
- Register the plugin in your module setup:
import { defineNuxtModule, addServerPlugin } from '@nuxt/kit'
import { fileURLToPath } from 'url'
export default defineNuxtModule({
setup(options, nuxt) {
const runtimeDir = fileURLToPath(new URL('./runtime', import.meta.url))
addServerPlugin(resolve(runtimeDir, 'server/plugins/my-module-llms'))
}
})
Nuxt Content ^3.2.0 comes with built-in support for LLMs documentation. You can use nuxt-llms
with @nuxt/content
to efficiently write content and documentation for your website and generate LLM-friendly documentation without extra effort. Content module uses nuxt-llms
hooks and automatically adds all your contents into llms.txt
and llms_full.txt
documentation.
All you need is to install both modules and write your content files in the content
directory.
export default defineNuxtConfig({
modules: ['nuxt-llms', '@nuxt/content'],
llms: {
domain: 'https://example.com',
title: 'My Application',
description: 'My Application Description',
},
})
Checkout the Nuxt Content documentation for more information on how to write your content files.
And checkout the Nuxt Contnet llms documentation for more information on how to customize LLMs contents with nuxt-llms
and @nuxt/content
.
- Clone repository
- Install dependencies using
pnpm install
- Prepare using
pnpm dev:prepare
- Build using
pnpm prepack
- Try playground using
pnpm dev
- Test using
pnpm test
Copyright (c) NuxtLabs