Watch the video demo on YouTube!
An AI-powered Wordle solver that uses browser automation and large language models to automatically play and solve Wordle puzzles.
- 🤖 AI-Powered: Uses OpenAI or OpenRouter APIs to generate intelligent word guesses
- 🌐 Browser Automation: Powered by Stagehand for reliable web interaction
- 🧠 Smart Strategy: Analyzes previous guesses and applies Wordle constraints for optimal play
- 🔄 Multiple LLM Support: Compatible with OpenAI, OpenRouter, and other LLM providers
- 🎛️ Configurable: Easy setup with environment variables
- Navigates to the New York Times Wordle website
- Generates intelligent word guesses using AI based on Wordle constraints
- Extracts color feedback (green/yellow/gray) from the game interface
- Analyzes results to build constraints for the next guess
- Repeats until the word is solved or maximum attempts reached
# Clone the repository
git clone https://github.com/CodingWithLewis/LLMs-Play-Wordle
cd LLMs-Play-Wordle
# Install dependencies
npm install
- Copy the example environment file:
cp .env.example .env
- Edit
.env
and add your API keys:
For Browser Automation (Browserbase - Recommended):
BROWSERBASE_API_KEY
: Get from BrowserbaseBROWSERBASE_PROJECT_ID
: Your Browserbase project ID
For LLM API:
OPENAI_API_KEY
: Get from OpenAI OROPENROUTER_API_KEY
: Get from OpenRouter
# LLM Provider: "openai" or "openrouter"
LLM_PROVIDER="openai"
# Model selection based on provider:
# For OpenAI: "o3-mini", "gpt-4o", "gpt-4o-mini", etc.
# For OpenRouter: "openai/o3-mini", "anthropic/claude-3-sonnet", etc.
LLM_MODEL="o3-mini"
npm start
To run with a local browser instead of Browserbase, modify stagehand.config.ts
:
env: "LOCAL" // Change from "BROWSERBASE" to "LOCAL"
Then run:
npm start
The bot uses a sophisticated constraint-based approach:
- First Guess: Uses common 5-letter words with good letter distribution
- Subsequent Guesses:
- Green letters: Fixed in correct positions
- Yellow letters: Must be included but not in guessed positions
- Gray letters: Excluded from future guesses
- Invalid words: Tracks and avoids words not in Wordle's dictionary
The AI receives prompts like:
Wordle constraints:
Word: ?R?I?
Must have: RAISE
Not at: pos1≠R, pos4≠I
Exclude: XTON
NOT these words (invalid): TRAIL, BRAIN
Give one 5-letter word:
wordlebot/
├── index.ts # Main application entry point
├── lib/
│ └── guessWord.ts # AI word generation logic
├── llm_clients/ # Custom LLM client implementations
├── stagehand.config.ts # Browser automation configuration
├── utils.ts # Utility functions
└── .env.example # Environment configuration template
- Node.js 18+
- API keys for:
- Browserbase (for cloud browser automation) OR local browser setup
- OpenAI or OpenRouter (for AI word generation)
# Build TypeScript
npm run build
# Development with auto-reload
npm run start
- "Word not in dictionary" errors: The bot automatically handles this by tracking invalid words and retrying
- Browser automation failures: Ensure your Browserbase API keys are correct, or try local mode
- LLM API errors: Check your API keys and rate limits
Make sure your .env
file has all required variables from .env.example
.
- Fork the repository
- Create a feature branch
- Make your changes
- Test thoroughly
- Submit a pull request
MIT License - see LICENSE file for details
- Built with Stagehand for browser automation
- Powered by Browserbase for cloud browser infrastructure
- Uses OpenAI and OpenRouter APIs for intelligent word generation
This bot is for educational purposes. Please use responsibly and in accordance with the New York Times' terms of service.