:frog: ModelHop
Save 60-90% on LLM costs by hopping to the right model.
ModelHop is an intelligent LLM router that automatically picks the cheapest capable model for each query. It uses multi-signal feature extraction, experience-based learning, and adaptive confidence thresholds to route simple queries to free models while reserving premium models for complex tasks.
:zap: Quick Start
pip install modelhop
modelhop init
modelhop route "How do I reset my password?"
:lock: Setup API Keys
Get at least one API key from a free provider:
| Provider | Key | Free Tier |
|---|---|---|
| Groq | console.groq.com | :white_check_mark: Yes |
| Google Gemini | aistudio.google.com | :white_check_mark: Yes |
| OpenAI | platform.openai.com | Paid |
Set your keys:
# Option 1: Interactive setup (recommended)
modelhop setup
# Option 2: Manual .env file
cp .env.example .env
# Edit .env with your keys
:hammer_and_wrench: Commands
| Command | Alias | Description |
|---|---|---|
modelhop route <query> |
modelhop r |
Route a query to the cheapest capable model |
modelhop setup |
modelhop set |
Interactive API key setup wizard |
modelhop init |
modelhop i |
Generate default config file |
modelhop stats |
modelhop s |
Show routing statistics |
modelhop history |
modelhop h |
Show recent query history |
modelhop providers |
modelhop p |
List available providers and models |
modelhop benchmark |
modelhop b |
Run benchmark queries |
modelhop config |
modelhop c |
Show current configuration |
modelhop example |
modelhop e |
Show example usage |
modelhop shield |
- | Show quality monitoring status |
modelhop hub |
- | Show community hub configs |
modelhop welcome |
- | Show welcome message |
:brain: How It Works
Query → Feature Extraction → AI Analysis → Learning Router → Model Selection
|
┌───────┴───────┐
│ Free Tier │
│ (Groq/Gemini)│
└───────┬───────┘
│
If complex/failed
│
┌───────┴───────┐
│ Premium Tier │
│ (GPT-4) │
└───────────────┘
Multi-Signal Analysis:
- Code keyword detection (algorithm, debugging, implementation)
- Query intent classification (explain, implement, debug, compare)
- Constraint detection (O(n), O(1), time/space complexity)
- Experience memory (past routing outcomes)
- Per-model performance tracking
- Adaptive confidence thresholds
Example:
# Simple query → Free model
modelhop r "What is Python?"
# Routes to: groq-qwen3-8-27b (FREE)
# Complex query → Premium model
modelhop r "Implement a red-black tree with O(log n) insertion"
# Routes to: openai-gpt-4 (PREMIUM)
# Failed premium → Automatic fallback
modelhop r "Complex query" # GPT-4 fails → falls back to Groq
:receipt: Cost Tracking
Every query shows cost savings:
╭────────────────────── Cost Analysis ──────────────────────╮
│ :moneybag: Actual cost: $0.0000 │
│ :x: Would cost (GPT-4): $0.0625 │
│ :sparkles: You saved: $0.0625 (100%) │
│ :tada: AMAZING SAVINGS │
╰──────────────────────────────────────────────────────────╯
:bar_chart: Verbose Mode
Add --verbose for full intelligence stats:
modelhop r "Implement quicksort" --verbose
Shows: feature extraction, AI analysis, experience memory, routing decision, hop score, and system intelligence stats.
:gear: Configuration
ModelHop uses a modelhop.yaml config file. Generate the default with:
modelhop init
Default models:
| Model | Provider | Tier | Cost |
|---|---|---|---|
qwen/qwen3.8-27b |
Groq | Free | $0.00 |
gemini-3.6-flash |
Free | $0.00 | |
gpt-4 |
OpenAI | Premium | $0.03/$0.06 per 1K |
:wrench: Development
# Clone the repo
git clone https://github.com/yourusername/modelhop.git
cd modelhop
# Install in dev mode
pip install -e ".[dev]"
# Run tests
pytest
# Format code
black modelhop/
# Lint
ruff check modelhop/
:package: Publishing
# Build
python -m build
# Upload to PyPI
twine upload dist/*
:memo: License
MIT License - see LICENSE for details.
:heart: Contributing
Contributions welcome! Please open an issue or PR.
Metadata
Release files for modelhop 1.0.7
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| modelhop-1.0.7.tar.gz | 72.0 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| modelhop-1.0.7-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 135.9 kB
Release files / modelhop-1.0.7.tar.gz
| Download URL | modelhop-1.0.7.tar.gz |
|---|---|
| Size | 72.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
398cc52024e4aa0c92bb999b629c4a0b5c5d0c5d23423f108455e49911bc1072
|
|
BLAKE2b-256 checksum How to use checksums |
c182970edddd5a8653272bce91bd572408589691419210a2cda10cf67f7e5356
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.6
|
Release files / modelhop-1.0.7-py3-none-any.whl
| Download URL | modelhop-1.0.7-py3-none-any.whl |
|---|---|
| Size | 63.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
d2b7cfd815c564e5a7b4f293c10d47a2bc9ad7af3a13d1e647f30852881b4b3a
|
|
BLAKE2b-256 checksum How to use checksums |
48a7cc8c700d91981e8a26a30050ab5c374ee23f61d36727df64f2caf12b63d7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.6
|