x_thread_archiver
Val Town is a collaborative website to build and scale JavaScript apps.
Deploy APIs, crons, & store data β all from the browser, and deployed in milliseconds.
Archive Twitter/X threads with Grok AI and optional OCR for images.
- Thread Fetching: Uses xAI's Grok API to fetch complete X/Twitter threads
- OCR Processing: Extract text from tweet images using Amazon Nova via OpenRouter
- Markdown Export: Generate markdown files with YAML frontmatter and save to blob storage
- Owner-Only Filtering: Option to exclude replies and show only thread author's tweets
- Interactive Web UI: Dashboard with comprehensive visual feedback
- Real-time loading states with animated spinners
- Clear success/error messages with emojis
- Auto-scrolling to messages for visibility
- Button disabling during operations (prevents double-submission)
- Smooth fade-in animations for all dynamic content
- Auto-dismiss success messages (5 seconds)
- RESTful API: Programmatic access for archiving and retrieving threads
individual_vals/x_thread_archiver/
βββ main.ts # HTTP handler + Web UI
βββ src/
β βββ types.ts # TypeScript interfaces
β βββ database.ts # SQLite operations
β βββ grok_client.ts # Grok API for thread fetching
β βββ ocr_client.ts # Amazon Nova OCR via OpenRouter
β βββ markdown.ts # Markdown generation and frontmatter
βββ deno.json # Deno configuration
βββ README.md # This file
Set these in Val Town Dashboard β Settings β Environment Variables:
XAI_API_KEY- xAI API key for Grok (required)OPENROUTER_API_KEY- OpenRouter API key for Amazon Nova OCR (required for OCR)X_THREAD_ARCHIVER_PASSWORD- Password for dual authentication (optional)
# Navigate to project directory cd individual_vals/x_thread_archiver # Initialize val (if not already done) vt init # Watch for changes and auto-deploy vt watch # Or manually push vt push
- Open the val URL in your browser
- Enter a Twitter/X thread URL
- Optionally enable owner-only filtering
- Optionally enable OCR for images
- Click "Archive Thread"
Archive a thread (POST /)
curl -X POST https://your-val.web.val.run \ -H "Content-Type: application/json" \ -H "X-API-Key: your-password" \ -d '{ "url": "https://x.com/username/status/123456789", "ownerOnly": true, "enableOCR": true, "ocrModel": "amazon/nova-2-lite-v1:free" }'
List archived threads (GET /?list)
curl https://your-val.web.val.run?list=true \ -H "X-API-Key: your-password"
Get specific thread (GET /?thread=ID)
curl https://your-val.web.val.run?thread=1 \ -H "X-API-Key: your-password"
Download markdown (GET /?download=BLOB_KEY)
curl https://your-val.web.val.run?download=x-threads/user_123_2025.md \ -H "X-API-Key: your-password"
Delete thread (GET /?delete=ID)
curl https://your-val.web.val.run?delete=1 \ -H "X-API-Key: your-password"
Supports dual authentication:
- X-API-Key header: For API/script access
- Basic Auth: For browser access (username:
admin, password: env var)
x_threads
- Stores thread metadata (author, tweet count, settings, blob key)
x_tweets
- Stores individual tweets with full data including images and engagement metrics
Generated markdown includes:
- YAML frontmatter with metadata
- Formatted tweets with engagement metrics
- Embedded images with optional OCR text
- Links back to original tweets
- Model:
grok-4-1-fast-reasoningfor thread fetching - Endpoint:
/responses(supports tools like x_search) - Tool:
x_searchfor accessing X/Twitter data - Test Function: Uses simple
/chat/completionsendpoint for fast API key validation
- Provider: OpenRouter API
- Models:
amazon/nova-2-lite-v1:free(default) oramazon/nova-2-pro-v1:free - Format: Images converted to JPEG base64 for compatibility
- Rate Limiting: 1 second delay between images, 3 retry attempts
# Run locally deno run --allow-all main.ts # Watch mode deno task dev
This Val is a TypeScript/Deno port of the Python script try_grok_nova.py, adapted for the Val Town platform.
MIT