@opuu/elysia-llms-txt
v1.1.0
Published
Elysia plugin to generate llms.txt from OpenAPI/Swagger specifications.
Maintainers
Readme
Elysia LLMs TXT
An Elysia plugin that generates llms.txt documentation from OpenAPI/Swagger specifications. Transform your API specs into LLM-friendly documentation with automatic endpoint generation.
Why Elysia LLMs TXT?
Elysia LLMs TXT bridges the gap between your API documentation and AI consumption, making it perfect for:
- LLM Integration: Generate AI-friendly documentation that large language models can easily parse
- API Documentation: Convert OpenAPI/Swagger specs into readable markdown format
- Developer Experience: Provide
/llms.txtendpoints for instant API documentation access - AI Training: Create structured documentation suitable for training AI models on your API
- Documentation Automation: Automatically generate and serve API documentation without manual maintenance
Key Features
- OpenAPI/Swagger Support: Works with both file-based and URL-based OpenAPI specifications
- JSON & YAML Support: Automatically detects and parses both JSON and YAML formats
- LLM-Optimized Output: Generates markdown documentation specifically formatted for AI consumption
- Elysia Native: Built specifically for Elysia with TypeScript support
- Flexible Configuration: Customizable headers, footers, and content types
- Standard Endpoints: Provides
/llms.txtand/llms-full.txtendpoints automatically - Built-in Caching: Optional LRU cache with configurable TTL and max size
Installation
npm install @opuu/elysia-llms-txtpnpm add @opuu/elysia-llms-txtyarn add @opuu/elysia-llms-txtbun add @opuu/elysia-llms-txtQuick Start
1. Basic Usage
import { Elysia } from "elysia";
import { llms } from "@opuu/elysia-llms-txt";
const app = new Elysia()
.use(
llms({
source: {
type: "url",
url: "/swagger/json",
},
})
)
.listen(3000);
// Visit: http://localhost:3000/llms.txt2. File-based Configuration
import { Elysia } from "elysia";
import { llms } from "@opuu/elysia-llms-txt";
const app = new Elysia()
.use(
llms({
source: {
type: "file",
file: "./openapi.json",
},
header: "# My API Documentation",
footer: "Generated for LLM consumption",
})
)
.listen(3000);3. Advanced Configuration
import { Elysia } from "elysia";
import { llms } from "@opuu/elysia-llms-txt";
const app = new Elysia()
.use(
llms({
source: {
type: "url",
url: "https://petstore.swagger.io/v2/swagger.json",
},
header: `# Petstore API Documentation
This documentation is optimized for Large Language Models.`,
footer: `
---
Last updated: ${new Date().toISOString()}
Generated by @opuu/elysia-llms-txt`,
contentType: "text/markdown",
})
)
.listen(3000);API Reference
Configuration Options
The plugin accepts an LLMsOptions object with the following properties:
| Option | Type | Description | Default |
| ------------- | --------------------------------- | ------------------------------------- | ----------------- |
| source | object | Source configuration for OpenAPI spec | Required |
| source.type | "file" \| "url" | Whether to load from file or URL | Required |
| source.file | string | File path (when type is "file") | Optional |
| source.url | string | URL path (when type is "url") | Optional |
| header | string | Optional header content | Optional |
| footer | string | Optional footer content | Optional |
| contentType | "text/markdown" \| "text/plain" | Response content type | "text/markdown" |
| cache | object | Cache configuration | Optional |
| cache.enabled | boolean | Enable response caching | false |
| cache.ttl | number | Cache TTL in milliseconds | 60000 |
| cache.maxSize | number | Max cache entries (LRU eviction) | 100 |
YAML Support
The plugin automatically detects and parses YAML OpenAPI specs. To enable YAML support, install js-yaml:
npm install js-yamlYAML files are detected by:
- File extension (
.yamlor.yml) - Content analysis (if not starting with
{or[)
Generated Endpoints
The plugin automatically adds these endpoints to your Elysia application:
GET /llms.txt- Returns the generated LLM documentationGET /llms-full.txt- Redirects to/llms.txt(for compatibility)
Requirements
- Node.js >= 18.0.0
- Bun >= 1.0.0
- Elysia >= 1.0.0
License
MIT License - see LICENSE file for details.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
