The storage module handles uploading generated llms.txt files to Cloudflare R2 (S3-compatible object storage). It uses boto3 for S3 API compatibility and generates deterministic filenames based on URL hashing.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/Anwitht21/llmstxt/llms.txt
Use this file to discover all available pages before exploring further.
Overview
The storage module provides a single async function for saving llms.txt content to R2:- MD5-based filename generation for consistent paths
- S3-compatible upload using boto3
- Public URL generation with custom domain support
- Graceful handling when storage is not configured
Configuration
Storage requires the following environment variables (fromconfig.settings):
r2_endpoint- R2 endpoint URLr2_access_key- R2 access key IDr2_secret_key- R2 secret access keyr2_bucket- Target bucket namer2_public_domain- Optional custom domain for public URLs
Functions
save_llms_txt()
Saves llms.txt content to R2 storage and returns the public URL.The base URL of the crawled site (used for filename generation)
The formatted llms.txt content to upload
Logging function (sync or async) that accepts string messages
Public URL of the uploaded file, or None if upload failed or storage not configured
- Checks if all required R2 settings are configured
- If not configured, logs message and returns None
- Creates boto3 S3 client with R2 credentials
- Generates MD5 hash of base URL for deterministic filename
- Uploads content with
text/markdowncontent type - Constructs public URL using custom domain or endpoint
- Logs upload success with URL
- Returns public URL on success, None on error
<md5_hash> is the MD5 hash of the base URL.
Usage Examples
Basic Upload
Integration with Crawler and Formatter
Without Storage Configured
Error Handling
Public URL Generation
The function generates public URLs in two ways:With Custom Domain
Ifsettings.r2_public_domain is set:
Without Custom Domain
Falls back to R2 endpoint:Filename Determinism
The MD5 hash ensures consistent filenames for the same base URL:- No need to track or delete old files
- Recrawls automatically update the same file
- Predictable URLs for integration
Content Type
Files are uploaded withContent-Type: text/markdown:
Error Handling
The function handles errors gracefully:- Invalid credentials →
ClientError - Network timeout →
ClientError - Bucket not found →
ClientError - Permission denied →
ClientError
None.
Dependencies
- boto3 - AWS SDK for S3-compatible operations
- botocore - Error handling for boto3
- config - Settings management
Related Modules
- formatter - Generates the content to upload
- database - Stores the public URL in Supabase
- config - Provides R2 configuration settings
Notes
- Function is async for consistency with other backend modules
- Boto3 operations are synchronous (no async boto3 used)
- Graceful degradation when storage not configured
- Public URLs are immediately accessible after upload
- No explicit public ACL needed (bucket configured for public reads)