A comprehensive tool for executing JSON prompt files using the OpenRouter API. Available as both a command-line interface (CLI) and a Flask web application. Choose the interface that best fits your workflow!
π First time using this tool? β QUICK START GUIDE - Get running in 3 minutes!
π Global Installation: New ./install-global.sh script enables CLI tools to run from any directory without virtual environments.
π§ Web Interface Fixed: Resolved "No prompts configured" issue - prompts now display correctly in the web interface.
π¦ Installation Improved: Fixed pyproject.toml and added proper setup.py for better pip compatibility.
π Entry Points Working: CLI commands (openrouter-runner, openrouter-chain, openrouter-web) now work as intended.
π Enhanced Documentation: Added comprehensive troubleshooting guide and updated all setup instructions.
π Get Started: Quick Start (QUICK-START.md) | Setup Guide (README_setup.md) | Linux Setup (SETUP_LINUX.md)
βοΈ Advanced: Prompt Chains (prompt_chain_readme.md) | Multi-File Processing
π Web Interface: Flask Setup (setup_guide.md) | Templates (README_temple_setup.md)
π§ Development: Claude Code Integration (CLAUDE.md) | Architecture Guide
π Help: Troubleshooting Guide (TROUBLESHOOTING.md) | Common Issues & Fixes
Perfect for automation, batch processing, and CI/CD pipelines:
- Batch mode: Process specific files directly
- Interactive mode: Browse and select files interactively
- Configuration management: YAML config files and command-line overrides
- Logging: File and console logging with multiple levels
Ideal for interactive use and team collaboration:
- Web interface: Modern, responsive design
- Session management: Track history and download results
- Configuration UI: Web-based settings management
- File uploads: Drag-and-drop file processing
Advanced automation for multi-step AI workflows:
- Sequential Processing: Execute 1-99 prompts in sequence
- Multi-File Support: Process multiple files through the same prompt chain
- Per-Prompt Configuration: Use different LLMs for each step (Claude, GPT-4, DeepSeek, etc.)
- Advanced File Management: Organized temp directories with full traceability
- Flexible Output: Pattern-based naming for batch processing
This project includes comprehensive documentation for all components and use cases:
- README_setup.md - Complete setup instructions for all platforms
- SETUP_LINUX.md - Linux-specific automated setup script documentation
- setup_guide.md - Step-by-step Flask web application setup guide
- README_temple_setup.md - HTML template setup for Flask interface
- prompt_chain_readme.md - Complete guide to Prompt Chain Runner for multi-step AI workflows
- CLAUDE.md - Developer guidance for Claude Code integration and project architecture
- compliance_analysis.md - Analysis framework and quality standards
- style_reference.md - Writing style guidelines and formatting standards
- analysis_framework.md - Document analysis methodology
For complete setup instructions, see the Setup Guide (README_setup.md).
Comprehensive Linux setup (recommended):
# Download project files, then run:
chmod +x setup_linux.sh
./setup_linux.sh # Install to ~/.local/bin (user)
./setup_linux.sh --system # Install to /usr/local/bin (system-wide, requires sudo)Legacy setup script:
chmod +x setup_prompt_runner.sh
./setup_prompt_runner.shThe Linux setup script will:
- β Verify Python 3.7+ installation
- β Install all required packages (requests, pyyaml, flask)
- β Make all entry point scripts executable
- β
Copy all modules to
~/.local/binor/usr/local/bin - β Copy shell scripts and make them executable
- β Verify installation and provide next steps
If you prefer manual installation, see the detailed instructions in README_setup.md.
Ensure you have all necessary Python modules:
project/
βββ prompt_runner.py # Main CLI application
βββ config_manager.py # Configuration handling
βββ logging_manager.py # Logging setup
βββ prompt_scanner.py # JSON prompt discovery
βββ prompt_handler.py # Prompt loading and processing
βββ input_handler.py # Input file handling
βββ prompt_runner_api_client.py # OpenRouter API client
βββ response_handler.py # Output handling
βββ file_handler.py # File operations
βββ *.json # Your JSON prompt files
βββ openrouter_editor.yaml # Optional config file
pip install requests pyyaml# Set your OpenRouter API key as environment variable
export OPENROUTER_API_KEY="your_api_key_here"
# Or add it to your config file (not recommended for security)
echo "api_key: your_api_key_here" >> openrouter_editor.yamlpython prompt_runner.py [OPTIONS]
Mode Selection:
-p, --prompt PROMPT_FILE JSON prompt file (enables batch mode)
-i, --input INPUT_FILE Input file to process (requires --prompt)
Configuration Options:
-c, --config CONFIG_FILE Configuration file (YAML format)
Output Options:
-o, --output-file OUTPUT Output file for responses (markdown)
Logging Options:
-l, --log-file LOG_FILE Log file path (enables file logging)
-v, --verbose Enable verbose logging (DEBUG level)
-q, --quiet Suppress output except errors
--temp-dir TEMP_DIR Temporary directory for logs and payload files
Help:
-h, --help Show help message and examplesCreate openrouter_editor.yaml:
# OpenRouter API Settings
model: anthropic/claude-4-sonnet-20250522
api_base_url: https://openrouter.ai/api/v1
temperature: 0.8
max_tokens: 25000
# Application Settings
log_level: INFO
log_to_file: false # Set true to enable file logging
log_file: prompt_runner.log # Automatically enables file logging
payload_file: prompt_runner.payload.json
# Input/Output Settings
input_file: input.md
output_file: output.md
action_file: action.json# Basic interactive mode - scan directory and select files
python prompt_runner.py
# Interactive with output file
python prompt_runner.py -o responses.md
# Interactive with custom config
python prompt_runner.py -c my_config.yaml -o responses.md
# Interactive with verbose logging to file
python prompt_runner.py -l debug.log -v -o responses.md# Basic batch processing
python prompt_runner.py -p analysis.json -i document.md
# Batch with output file
python prompt_runner.py -p review.json -i code.py -o results.md
# Batch with custom config
python prompt_runner.py -p analysis.json -i data.txt -c config.yaml -o analysis.md
# Batch with logging
python prompt_runner.py -p review.json -i code.py -l batch.log -o results.md# Process multiple files with same prompt - perfect for automation
python prompt_runner.py -p review.json -i file1.md -o results.md -l batch.log
python prompt_runner.py -p review.json -i file2.md -o results.md -l batch.log
python prompt_runner.py -p review.json -i file3.md -o results.md -l batch.log
# Or use a loop for many files
for file in *.md; do
python prompt_runner.py -p review.json -i "$file" -o results.md -l batch.log
done# Command line log file overrides config
python prompt_runner.py -c config.yaml -l custom.log -p analysis.json -i doc.md
# Mix command line and config file settings
python prompt_runner.py -c base_config.yaml -p custom_prompt.json -i input.txt -l debug.log -v
# Use custom temp directory for organized file management
python prompt_runner.py -p analysis.json -i document.md --temp-dir temp/analysis_run# Debug a specific prompt with verbose logging
python prompt_runner.py -p debug_prompt.json -i test_input.md -l debug.log -v
# Quick test without saving output
python prompt_runner.py -p test.json -i sample.md -q
# Test with different models using config
python prompt_runner.py -c gpt4_config.yaml -p analysis.json -i document.md# Process a batch of documents with consistent logging
mkdir -p logs outputs
for doc in inputs/*.md; do
filename=$(basename "$doc" .md)
python prompt_runner.py \
-p production_review.json \
-i "$doc" \
-o "outputs/${filename}_review.md" \
-l "logs/batch_$(date +%Y%m%d).log" \
-c production_config.yaml
done# Automated analysis in CI pipeline
python prompt_runner.py \
-p code_review.json \
-i src/main.py \
-o reports/code_analysis.md \
-l logs/ci_analysis.log \
-c ci_config.yaml || exit 1
# Exit code 0 = success, 1 = failure (perfect for scripts)# Normal operation shows progress
$ python prompt_runner.py -p analysis.json -i document.md
2025-01-26 10:30:15 - INFO - Initializing OpenRouter Prompt Runner
2025-01-26 10:30:15 - INFO - β Files validated successfully
2025-01-26 10:30:15 - INFO - β Prompt loaded successfully
2025-01-26 10:30:15 - INFO - β Input content loaded
2025-01-26 10:30:16 - INFO - β API call successful
β Successfully processed document.md with analysis.jsonWhen using -l or config file logging:
================================================================================
NEW SESSION STARTED
================================================================================
2025-01-26 10:30:15 - INFO - Initializing OpenRouter Prompt Runner
2025-01-26 10:30:15 - INFO - Command line log file specified: batch.log
2025-01-26 10:30:15 - INFO - β Logging to file: batch.log
2025-01-26 10:30:15 - INFO - Model: anthropic/claude-4-sonnet-20250522
2025-01-26 10:30:15 - INFO - API call completed in 1.23 seconds
2025-01-26 10:30:15 - INFO - β Batch processing completed successfully
When using -o output.md:
## Prompt Response - 2025-01-26 10:30:16
**Prompt File:** `analysis.json`
**Input File:** `document.md`
**Timestamp:** 2025-01-26 10:30:16
---
[AI Response Content Here]
---# CLI validates files at startup
$ python prompt_runner.py -p missing.json -i document.md
ERROR: Prompt file not found: missing.json
$ python prompt_runner.py -p analysis.json -i missing.md
ERROR: Input file not found: missing.md- Command line options (highest priority)
- Config file settings (
-c config.yaml) - Default configuration
- File logging: Automatically enabled when log file specified
- Batch mode: Triggered when both
-pand-iprovided - Directory creation: Log and output directories created automatically
- Unique payload files: Each execution creates timestamped payload files (
prompt_runner_20250131_143052_12345.payload.json) - Temporary directory support: Use
--temp-dirto organize all files in one location - Shared temp directories: When used with prompt chains, all files stored in the same temp directory
- File preservation: Payload files preserved after execution for debugging and review
1. API Key Not Found
$ python prompt_runner.py -p test.json -i input.md
ERROR: API key not found
# Solution:
export OPENROUTER_API_KEY="your_key_here"2. Missing Dependencies
$ python prompt_runner.py
ModuleNotFoundError: No module named 'yaml'
# Solution:
pip install pyyaml requests3. File Permission Errors
$ python prompt_runner.py -p test.json -i input.md -l /restricted/log.log
ERROR: Failed to save payload
# Solution:
python prompt_runner.py -p test.json -i input.md -l ./log.log4. Invalid JSON Prompts
$ python prompt_runner.py -p broken.json -i input.md
ERROR: Invalid JSON in prompt file broken.json
# Solution: Validate JSON format
python -m json.tool broken.jsonThe easiest way to run the Flask web application:
# Make the launcher script executable
chmod +x prompt_runner_flask.sh
# Run initial setup (creates templates and config)
./prompt_runner_flask.sh --setup
# Start the web application
./prompt_runner_flask.sh
# Or start in production mode
./prompt_runner_flask.sh --productionThe prompt_runner_flask.sh script provides convenient management:
# Basic usage
./prompt_runner_flask.sh # Start with defaults (127.0.0.1:5000)
./prompt_runner_flask.sh -d # Debug mode
./prompt_runner_flask.sh -H 0.0.0.0 -p 8080 # Custom host and port
# Management commands
./prompt_runner_flask.sh --setup # Create templates and config
./prompt_runner_flask.sh --check # Verify dependencies
./prompt_runner_flask.sh --background # Run as daemon
./prompt_runner_flask.sh --kill # Stop background instances
./prompt_runner_flask.sh --logs # View application logs
# Production deployment
./prompt_runner_flask.sh --production # Production settings (0.0.0.0, no debug)
./prompt_runner_flask.sh --public # Public access (0.0.0.0)- Dependency checking: Validates Python, Flask, and required modules
- Automatic setup: Creates templates and configuration files
- Process management: Start, stop, and monitor background processes
- Logging: File and console logging with real-time viewing
- Error handling: Clear error messages and recovery suggestions
If you prefer to run Flask directly:
If you prefer to run Flask directly:
project/
βββ prompt_runner_flask.py # Flask web application
βββ create_templates.py # Template setup script
βββ flask_config.yaml # Web app configuration
βββ prompts_registry.yaml # Prompt registry
βββ templates/ # HTML templates directory
β βββ base.html # Base template
β βββ index.html # Main page
β βββ config.html # Configuration page
β βββ prompts_registry.html # Registry management
β βββ prompt_form.html # Prompt execution form
β βββ history.html # Session history
βββ [CLI files from above] # All CLI files also needed
# Install additional web dependencies
pip install flask
# Create templates and configuration
python create_templates.py
# Set API key
export OPENROUTER_API_KEY="your_api_key_here"
# Start web application
python prompt_runner_flask.pyNavigate to: http://localhost:5000
The Prompt Chain Runner (prompt_chain_runner.py) enables advanced automation workflows by executing multiple prompts in sequence. Perfect for complex document processing pipelines that require multiple AI processing steps.
Process multiple files through the same prompt chain:
# Process 3 files through the same 3-step prompt chain
python prompt_chain_runner.py -c multi_file_config.yamlConfiguration Example:
input_files:
- "document1.md"
- "document2.md"
- "document3.txt"
output_pattern: "processed_{input_name}_final{input_ext}"
prompts:
prompt 1: "analysis.json"
prompt 2: "refinement.json"
prompt 3: "polish.json"Use different AI models optimized for each step:
# Use Claude for creative tasks, GPT-4 for technical analysis
python prompt_chain_runner.py -c multi_llm_config.yamlConfiguration Example:
input_file: "document.md"
output_file: "processed_document.md"
prompts:
prompt 1:
prompt_file: "creative_brainstorm.json"
config_file: "claude_config.yaml" # Claude for creativity
prompt 2:
prompt_file: "technical_analysis.json"
config_file: "gpt4_config.yaml" # GPT-4 for technical work
prompt 3:
prompt_file: "final_polish.json"
config_file: "deepseek_config.yaml" # DeepSeek for final reviewSingle File Processing:
input.md β Analysis β Refinement β Polish β output.md
Multi-File Processing:
doc1.md β Analysis β Refinement β Polish β processed_doc1_final.md
doc2.md β Analysis β Refinement β Polish β processed_doc2_final.md
doc3.txt β Analysis β Refinement β Polish β processed_doc3_final.txt
All execution artifacts are preserved in organized temp directories:
temp/input_document_20250131_143052_12345/
βββ input_document_20250131_143052_12345.log # Execution log
βββ original_input_document.md # Original input
βββ file01_step01_analysis.tmp # Intermediate files
βββ file01_step02_refinement.tmp
βββ prompt_runner_20250131_143053_12346.payload.json # API payloads
βββ prompt_runner_20250131_143054_12347.payload.json
βββ processed_document_final.md # Final output copy
1. Create Configuration:
# Generate sample config
python prompt_chain_runner.py --create-sample2. Run Single File Chain:
python prompt_chain_runner.py -c my_chain.yaml3. Run Multi-File Processing:
python prompt_chain_runner.py -c multi_file_config.yaml4. Debug with Verbose Logging:
python prompt_chain_runner.py -c config.yaml --debugFor complete details, see prompt_chain_readme.md
This application works with 400+ AI models through OpenRouter.ai, including the most popular LLMs:
-
OpenAI
- GPT-4o:
openai/gpt-4o-2024-11-20 - GPT-4.5:
openai/gpt-4.5-preview - o3-mini:
openai/o3-mini
- GPT-4o:
-
Claude (Anthropic)
- Claude 4 Sonnet:
anthropic/claude-4-sonnet-20250522 - Claude 3.7 Sonnet:
anthropic/claude-3.7-sonnet - Claude 3.5 Sonnet:
anthropic/claude-3.5-sonnet:beta
- Claude 4 Sonnet:
-
Gemini (Google)
- Gemini 2.5 Pro:
google/gemini-2.5-pro-exp-03-25 - Gemini 2.0 Flash:
google/gemini-2.0-flash-experimental - Gemini Pro:
google/gemini-pro-1.5-latest
- Gemini 2.5 Pro:
-
DeepSeek
- DeepSeek R1:
deepseek/deepseek-r1 - DeepSeek V3:
deepseek/deepseek-chat-v3-0324 - DeepSeek Coder:
deepseek/deepseek-coder
- DeepSeek R1:
-
Llama (Meta)
- Llama 4 Maverick:
meta-llama/llama-4-maverick - Llama 3.3 70B:
meta-llama/llama-3.3-70b-instruct - Llama 3.1 Nemotron:
nvidia/llama-3.1-nemotron-70b-instruct
- Llama 4 Maverick:
-
Grok (xAI)
- Grok Beta:
x-ai/grok-beta - Grok 2:
x-ai/grok-2-1212
- Grok Beta:
-
Qwen (Alibaba)
- Qwen 3:
qwen/qwen-3-turbo - Qwen 2.5 Coder:
qwen/qwen-2.5-coder-32b-instruct - QwQ:
qwen/qwq-32b-preview
- Qwen 3:
-
Mistral
- Mistral Large:
mistralai/mistral-large-2411 - Mistral Small:
mistralai/mistral-small-3.1-24b-instruct - Pixtral:
mistralai/pixtral-12b-2409
- Mistral Large:
-
Cohere
- Command R+:
cohere/command-r-plus - Command R7B:
cohere/command-r7b-12-2024 - Command R:
cohere/command-r
- Command R+:
-
Amazon Nova
- Nova Pro:
amazon/nova-pro-v1 - Nova Lite:
amazon/nova-lite-v1 - Nova Micro:
amazon/nova-micro-v1
- Nova Pro:
-
Dolphin (Cognitive Computations)
- Dolphin Mixtral 8x7B:
cognitivecomputations/dolphin-mixtral-8x7b - Dolphin Mixtral 8x22B:
cognitivecomputations/dolphin-mixtral-8x22b - Dolphin 2.6 Mixtral:
cognitivecomputations/dolphin-2.6-mixtral-8x7b
- Dolphin Mixtral 8x7B:
-
Venice.ai Models (via direct API or OpenRouter)
- Venice Large (Qwen3): Use Venice.ai API directly
- Venice Medium: Use Venice.ai API directly
- Venice Small: Use Venice.ai API directly
- Note: Venice.ai has its own API separate from OpenRouter
- Website: https://venice.ai
- API URL: https://api.venice.ai/api/v1
Many models offer free tiers with rate limits. Add :free suffix to model names:
deepseek/deepseek-chat:freemeta-llama/llama-4-maverick:freegoogle/gemini-2.5-pro-exp-03-25:freemistralai/mistral-small-3.1-24b-instruct:freecognitivecomputations/dolphin-mixtral-8x7b:free
Venice.ai provides private, uncensored AI models through their own API. To use Venice models:
- Direct Venice API: Set up a Venice.ai account and use their API directly
- Model Configuration: Update
api_base_urltohttps://api.venice.ai/api/v1 - Available Models:
llama-3.3-70b,deepseek-r1-llama-70b,qwen32b,dolphin-2.9.2-qwen2
Note: Venice.ai requires separate API credentials and is not part of OpenRouter
Configure your preferred model in the configuration file or web interface:
CLI Configuration (openrouter_editor.yaml):
model: anthropic/claude-4-sonnet-20250522 # Default model
temperature: 0.8
max_tokens: 25000Web Configuration (flask_config.yaml):
model: anthropic/claude-4-sonnet-20250522 # Default model
temperature: 0.8
max_tokens: 10000- Batch Processing: Automated file processing for CI/CD pipelines
- Interactive Mode: Browse and select files with guided prompts
- Configuration Management: YAML config files with command-line overrides
- Flexible Logging: Console and file logging with multiple levels
- File Validation: Comprehensive input validation and error handling
- Session Persistence: Append logging for batch processing workflows
- Modern Interface: Clean, responsive design with mobile support
- Session History: Track all responses with download capability
- Configuration UI: Web-based settings management
- File Uploads: Support for text input and file uploads
- Live Updates: Real-time processing with AJAX
- Prompts Registry: Web-based prompt management
- Quick setup: Need to get started fast with minimal configuration
- Development: Testing and debugging with built-in process management
- Production deployment: Running on servers with monitoring needs
- Process management: Need to start/stop/monitor the application
- Logging: Want centralized log management and viewing
- Automation: Integrating with scripts, CI/CD, or batch processing
- Performance: Processing many files efficiently
- Scripting: Building automated workflows
- Headless: Running on servers without GUI
- Version Control: Configuration files can be tracked in git
- Interactive Use: Exploring prompts and experimenting
- Team Collaboration: Sharing access with multiple users
- File Uploads: Processing files through web interface
- Visual Feedback: Need immediate visual feedback
- Session Management: Tracking history within sessions
- API Key Protection: Store your OpenRouter API key as an environment variable
- File Upload Limits: Configure appropriate upload size limits (web interface)
- Input Validation: All inputs are validated before processing
- File Permissions: Ensure proper read/write permissions for config and log files
- Session Management: Web sessions are memory-based and cleared on restart
Create custom prompts in JSON format:
{
"instruction": "Analyze the following text for sentiment",
"type": "analysis",
"requirements": [
"Identify overall sentiment (positive/negative/neutral)",
"Highlight key emotional indicators",
"Provide confidence score"
],
"output_format": "structured analysis with clear sections"
}- CLI Features: Modify
prompt_runner.pyand related modules - Web Features: Add routes to
prompt_runner_flask.pyand create templates - Configuration: Add new settings to config management system
- API Integration: Extend API client for new functionality
Core Requirements:
requests- HTTP client for API callspyyaml- YAML configuration handlingpathlib- File path handling (built-in)json- JSON processing (built-in)logging- Logging system (built-in)
Web Interface Additional:
flask- Web framework for GUI
- DEBUG: Detailed debugging information
- INFO: General operational messages
- WARNING: Warning messages for potential issues
- ERROR: Error messages for failed operations
# Console logging (default)
python prompt_runner.py -p test.json -i input.md
# File logging
python prompt_runner.py -p test.json -i input.md -l debug.log
# Verbose console logging
python prompt_runner.py -p test.json -i input.md -v
# Quiet mode (errors only)
python prompt_runner.py -p test.json -i input.md -q- Missing Files: Ensure all required Python modules are present
- API Key: Set
OPENROUTER_API_KEYenvironment variable - Dependencies: Install required packages with
pip install requests pyyaml - Permissions: Check file read/write permissions
- JSON Format: Validate prompt files with
python -m json.tool file.json
- Templates Missing: Run
python create_templates.py - Config Missing: Check
flask_config.yamlexists - Port Conflicts: Flask runs on port 5000 by default
- File Uploads: Check upload size limits in configuration
# Reinstall dependencies
pip install --upgrade requests pyyaml flask
# Check file permissions
ls -la *.py *.yaml *.json
# Validate JSON prompts
for file in *.json; do python -m json.tool "$file" >/dev/null && echo "$file: OK" || echo "$file: ERROR"; done
# Test API key
echo $OPENROUTER_API_KEY- Fork the repository
- Create a feature branch
- Make your changes with appropriate tests
- Update documentation for new features
- Test both CLI and web interfaces
- Submit a pull request
This project is provided as-is for educational and development purposes. Please ensure compliance with OpenRouter's terms of service when using their API.
For issues and questions:
- Check the troubleshooting section above
- Review configuration files and logs
- Verify API key and network connectivity
- Test with simple prompts first
- Check file permissions and dependencies
This project includes several specialized utilities for different use cases:
- BookGen Utilities - AI-powered book chapter generation and editing
bookGen.py- Main book generation applicationbookFileManager.py- File management for book content- Smart text chunking, action-based prompts, comprehensive logging
generateProse.py- Prose generation utilityopenrouter_editor.py- Original text editor interfacecallAPI.py- Basic API testing utility
Setup & Installation:
- Quick Start Guide - Get running in 3 minutes
- Complete Setup Guide - Detailed installation instructions
- Linux Automated Setup - Linux-specific setup script
- Flask Web Setup - Web interface setup guide
- Template Setup - HTML template configuration
Advanced Features:
- Prompt Chain Runner - Multi-step AI workflows
- BookGen Utilities - Book generation tools
- Claude Code Integration - Developer architecture guide
Reference Materials:
- Compliance Analysis - Quality standards framework
- Style Reference - Writing style guidelines
- Analysis Framework - Document analysis methodology
Configuration Examples:
config.yaml- Main application configurationflask_config.yaml- Web interface settingsbookGen.yaml- Book generation configurationopenrouter_editor.yaml- Legacy editor settings
Happy Prompting with CLI and Web! π