Skip to main content

ModelHop Frog


ModelHop

Save 60-90% on LLM costs by hopping to the right model.

CI Status PyPI Version Python Versions License


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.

Quick Start

# Install
pip install modelhop

# Initialize config
modelhop init

# Route your first query
modelhop route "How do I reset my password?"

Setup API Keys

Get at least one API key from a free provider:

Provider Key Free Tier
Groq console.groq.com Yes
Google Gemini aistudio.google.com 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

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

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

Examples:

# 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

Cost Tracking

Every query shows cost savings:

╭────────────────────── Cost Analysis ──────────────────────╮
│ Actual cost:          $0.0000                             │
│ Would cost (GPT-4):  $0.0625                             │
│ You saved:            $0.0625 (100%)                      │
│ AMAZING SAVINGS                                           │
╰──────────────────────────────────────────────────────────╯

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.

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 Google Free $0.00
gpt-4 OpenAI Premium $0.03/$0.06 per 1K

Development

# Clone the repo
git clone https://github.com/aalok101singh/modelhop.git
cd modelhop

# Install in dev mode
pip install -e ".[dev]"

# Run tests
pytest

# Format code
black modelhop/

# Lint
ruff check modelhop/

Publishing

# Build
python -m build

# Upload to PyPI
twine upload dist/*

Contributing

Contributions welcome! Please see CONTRIBUTING.md for guidelines.

License

MIT License - see LICENSE for details.

Security

For security vulnerabilities, please see SECURITY.md.

Changelog

See CHANGELOG.md for version history.


Made with love by Aalok

Metadata

Release files for modelhop 1.0.8

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for modelhop 1.0.8
File Size Uploaded
modelhop-1.0.8.tar.gz 51.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for modelhop 1.0.8
File Interpreter ABI Platform
modelhop-1.0.8-py3-none-any.whl Python 3 none any Details

Total release size: 116.2 kB

Release files / modelhop-1.0.8.tar.gz

Download URL modelhop-1.0.8.tar.gz
Size 51.8 kB
Tags Source
SHA-256 checksum
How to use checksums
1acca235dbf8d2463093f87d154053239b04952adf26f5800c229a52e243a5e3
BLAKE2b-256 checksum
How to use checksums
6af9b2c24da0ef567e5e3bb9c9709ef0dbbf0749b4c4f5b8e84166a7278c980c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / modelhop-1.0.8-py3-none-any.whl

Download URL modelhop-1.0.8-py3-none-any.whl
Size 64.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5a846f28bad446f48f5f7283d28bc89ec94a679269e571fc4d76ccf1f9131afd
BLAKE2b-256 checksum
How to use checksums
a18fb2dcb943156ab88d9ca256ffd5ff5ccf94618c517054a678852fdc495247
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release history Release notifications | RSS feed

1.1.0

2 release files

This release

1.0.8 This release

2 release files

1.0.7

2 release files

1.0.6

2 release files

1.0.5

2 release files

1.0.4

2 release files

1.0.3

2 release files

1.0.2

2 release files

1.0.1

2 release files

1.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page