Overview
The llms.txt Generator provides real-time feedback during crawling through WebSocket connections. Every step of the crawling process is streamed to the client, allowing users to monitor progress, debug issues, and receive results as they’re generated.Why WebSockets?
Traditional HTTP requests are synchronous - you send a request and wait for a complete response. Crawling a website can take 30-120 seconds depending on size, making this a poor user experience.HTTP Request
- Single request/response
- No progress updates
- Long wait time
- No visibility into errors
WebSocket Stream
- Persistent bidirectional connection
- Real-time log streaming
- Immediate feedback
- Live error reporting
WebSocket Endpoint
The API exposes a single WebSocket endpoint for crawling:backend/main.py
The
log callback is passed directly to the crawler, enabling real-time message streaming at every step of the process.Message Types
The WebSocket sends JSON messages with different types:Log Messages
Progress updates and status information:Result Message
The complete llms.txt content:URL Message
The hosted CDN URL for the generated file:Error Message
Any errors encountered during crawling:Authentication
WebSocket connections require authentication via query parameters:- JWT Token (Recommended)
- Direct API Key
Obtain a short-lived token from the Response:Use the token in WebSocket connection:
/auth/token endpoint:Client Implementation
Log Streaming in Action
Here’s what a typical crawl log stream looks like:Error Handling
WebSocket errors should be handled gracefully:Connection Lifecycle
1
Authentication
Client obtains a JWT token or uses API key directly
2
Connection
WebSocket connection established with authentication in query params
3
Request
Client sends JSON payload with crawl configuration
4
Streaming
Server streams log messages, progress updates, and status information
5
Result
Complete llms.txt content is sent when crawling completes
6
URL
Hosted CDN URL is sent after successful upload
7
Closure
Connection closes gracefully after all data is transmitted
Best Practices
Use JWT tokens in production
Use JWT tokens in production
JWT tokens expire after 5 minutes, limiting the damage if intercepted. Generate fresh tokens for each crawl session.
Buffer log messages
Buffer log messages
If logs arrive faster than they can be displayed, buffer them and render in batches to avoid UI performance issues.
Implement reconnection
Implement reconnection
For long-running crawls, implement exponential backoff reconnection logic to handle temporary network issues.
Handle partial results
Handle partial results
If the connection drops before completion, you may receive partial results. Store intermediate data and allow resume functionality.
Next Steps
Intelligent Crawling
Learn how the BFS crawler discovers and extracts content
Auto Updates
Set up scheduled recrawls to keep content fresh