Skip to main content

Overview

The WebSocket endpoint provides real-time bidirectional communication for crawling websites and generating llms.txt files. It streams progress updates, logs, and results as the crawl happens.

Endpoint

Authentication

The endpoint supports two authentication methods: Obtain a short-lived JWT token from the /auth/token endpoint and pass it as a query parameter:

Method 2: API Key

Pass your API key directly as a query parameter:
API keys are long-lived credentials. For production use, prefer JWT tokens which expire after 5 minutes.

Request Format

After connecting, send a JSON payload with the crawl configuration:
string
required
The base URL of the website to crawl. Must be a valid HTTP/HTTPS URL.Example: "https://example.com"
integer
default:50
Maximum number of pages to crawl. Used to prevent excessive crawling.Range: 1-1000
integer
default:500
Maximum length of description excerpts in characters. Truncated at semantic boundaries.Range: 100-2000
boolean
default:false
Enable automatic periodic recrawls for this site. Stores site metadata in the database.
integer
default:10080
Minutes between automatic recrawls (default: 7 days). Only used if enableAutoUpdate is true.Common values:
  • 360 (6 hours)
  • 1440 (1 day)
  • 10080 (1 week)
boolean
default:false
Use AI (Grok 4.1-Fast) to enhance and optimize the generated llms.txt content. Requires OPENROUTER_API_KEY and LLM_ENHANCEMENT_ENABLED=true.
boolean
default:true
Use Brightdata’s Scraping Browser for JavaScript-heavy sites. Falls back to Playwright if unavailable.

Example Request

Response Format

The server sends JSON messages with different types throughout the crawl process:

Log Messages

string
Always "log" for progress updates
string
Human-readable log message describing the current operation

Result Message

string
Always "result" for the generated llms.txt content
string
The complete generated llms.txt file in Markdown format

URL Message

string
Always "url" for the hosted file URL
string
Public CDN URL where the llms.txt file is hosted (Cloudflare R2)

Error Message

string
Always "error" for error conditions
string
Error description

Connection Flow

  1. Connect: Open WebSocket with authentication parameter
  2. Authenticate: Server validates token/API key
  3. Send Request: Client sends crawl configuration JSON
  4. Receive Logs: Server streams progress updates in real-time
  5. Receive Result: Server sends complete llms.txt content
  6. Receive URL: Server sends hosted file URL (if R2 configured)
  7. Close: Connection closes automatically after completion

Error Handling

Authentication Errors

Invalid Token
Missing API Key

Runtime Errors

Runtime errors are sent as JSON error messages before the connection closes:
Common error messages:
  • "Invalid URL format"
  • "Failed to fetch page: [details]"
  • "Crawl timeout exceeded"
  • "Maximum pages limit reached"

Example Implementation

JavaScript/TypeScript

Python

Rate Limits

  • No explicit rate limits on the WebSocket endpoint
  • Crawling is limited by maxPages parameter
  • Consider backend resource usage when setting high maxPages values
  • Use enableAutoUpdate to avoid manual repeated crawls

Best Practices

  1. Use JWT tokens instead of API keys for better security
  2. Set reasonable maxPages limits (50-100 for most sites)
  3. Enable auto-update for sites that change frequently
  4. Handle all message types in your client code
  5. Implement reconnection logic for production use
  6. Validate URLs before sending to prevent errors
  7. Use Brightdata (useBrightdata: true) for JavaScript-heavy sites