Skip to main content

ModelHop Frog


🐸 ModelHop

Stop overpaying for AI. Every query hops to the cheapest model that can handle it.

CI Status PyPI Version Python Versions License

CLI · Python SDK · OpenAI-compatible server — one brain, many bodies 🐸


Asking GPT-4 "what is Python?" is like taking a taxi to your mailbox. ModelHop routes each query to the cheapest model capable of answering it — free models for the easy stuff, premium muscle only when it earns its keep — and shows you exactly what you saved on every single call.

$ modelhop r "What is Python?"

  🎯 Routed to groq-qwen3-8-27b 🆓 FREE

  💸 Cost Analysis
  💰 Actual cost:               $0.0000
  ❌ Would cost (openai-gpt-4):  $0.0010
  ✨ You saved:                 $0.0010 (100%)
  🎉 AMAZING SAVINGS

Start hopping in 60 seconds 🐸

1. Install

pip install modelhop

2. Add one free key — grab one at console.groq.com or aistudio.google.com, then:

modelhop init     # creates modelhop.yaml, then offers to run setup
modelhop setup    # paste your key; broken models get tested alternatives

3. Route your first query

modelhop r "How do I reset my password?"
modelhop stats    # lifetime savings, hop score, latency

That's it. No config editing, no SDK keys to juggle — if a provider renames a model or your key lacks access, setup tells you the real reason and offers a working alternative.

Three ways to hop — pick yours 🐸

🖥️ CLI 🐍 Python SDK 🌐 Server
Use it for Daily questions, quick checks Your app or agent Any framework, any language
Install pip install modelhop pip install modelhop pip install "modelhop[server]"
First run modelhop r "hi" await ModelHop().route("hi") modelhop serve → model="auto"
Best at Zero-friction routing + savings dashboard Budgets, trust rules, tool context per call Drop-in OpenAI-compatible endpoint

CLI — beautiful terminal output with cost panels, hop scores, token counts, and --json for scripts:

modelhop r "Implement quicksort" --verbose   # full routing rationale
modelhop r "Summarize this log" --json       # machine-readable + tokens
modelhop providers                           # live status with real failure reasons

Python SDK — async-first, same brain as the CLI:

import asyncio
from modelhop import ModelHop

async def main():
    mh = ModelHop()
    r = await mh.route(
        "Explain SQL vs NoSQL",
        budget=0.05,                      # hard spend cap for this task
        trust_required={"zdr": True},     # hard privacy constraint
    )
    print(r.response)                     # the answer
    print(r.model, r.cost.savings)        # where it went, what you saved
    print(mh.explain(r))                  # one-line why

asyncio.run(main())

Server — point any OpenAI client at it, change nothing else:

from openai import OpenAI
client = OpenAI(base_url="http://127.0.0.1:8000/v1", api_key="not-needed-locally")
client.chat.completions.create(model="auto", messages=[{"role": "user", "content": "hi"}])

Streaming, /v1/models, optional Bearer auth (MODELHOP_API_KEY), rate limits and body caps included.

Why frogs hop smarter 🐸

  • 🧠 Cheapest capable model, every time — multi-signal analysis (intent, complexity, code cues, constraints) plus experience memory picks the tier; premium models only fire when the query earns it.
  • 💰 Savings on every call — actual vs would-have cost, tokens in/out, and a hop score, printed per query and aggregated in stats (lifetime totals, --reset to clear).
  • 🛡️ Fail-closed by default — low-confidence answers pin to the safest fallback and say so (degraded - low confidence…, never silent); cascade fallback rides through provider outages.
  • 📚 Self-improving — outcomes feed a contextual bandit + adaptive confidence threshold; calibration, shadow→canary rollouts, and drift auto-rollback keep it honest.
  • 🔍 Auditable — hash-chained signed ledger, JSONL traces, quality shield, OTel spans. Your keys never touch logs or traces.
  • 🤖 Agent-ready — MCP tool hook (mcp_tool_hook), LlamaIndex wrapper (pip install "modelhop[llamaindex]"), task budgets, session pinning, and trust policies.
  • 🔌 Honest wiring — setup probes live endpoints and reports the real error (bad key? no credits? model retired?) instead of "check your key", then offers tested replacements.

Providers 🐸

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 tokens

Free tier covers everyday questions; complex reasoning and code escalate to premium automatically. No mid tier? Fallback skips straight from free to premium. OpenAI needs prepaid billing credits before any of its models respond — setup will tell you exactly that.

Commands at a glance 🐸

Command Alias What it does
modelhop – Welcome guide — validates keys live, shows next steps
modelhop route <query> r Route a query (--json, --verbose, --model)
modelhop setup set Interactive key wizard with model fallback
modelhop init i Generate modelhop.yaml
modelhop stats s Lifetime stats (--reset to clear)
modelhop history h Recent routing decisions (+ tokens in JSON)
modelhop providers p Provider status with honest failure reasons
modelhop benchmark b Cost comparison test
modelhop config c Show current configuration
modelhop example e Example queries
modelhop cheat – Quick reference card
modelhop shield – Quality monitoring status
modelhop hub – Community configs
modelhop eval – Offline eval + drift check
modelhop calibrate – Confidence calibration
modelhop serve – OpenAI-compatible HTTP server

Piped output stays clean everywhere: no ANSI colors, ASCII frames, and emoji stripped when stdout isn't a terminal (plus NO_COLOR / MODELHOP_PLAIN=1 support).

Documentation 🐸

Development 🐸

git clone https://github.com/aalok101singh/modelhop.git
cd modelhop
pip install -e ".[dev,server]"

pytest --cov=modelhop --cov-fail-under=60   # 255 tests, hermetic (no live keys needed)
ruff check modelhop/ tests/
black --check modelhop/ tests/

Contributing 🐸

Contributions welcome! Please see CONTRIBUTING.md for guidelines.

License 🐸

MIT License — see LICENSE for details.

Security 🐸

Found a vulnerability? Please see SECURITY.md — don't open a public issue.

Changelog 🐸

See CHANGELOG.md for version history.


🐸 Made with love by Aalok — hop smart, pay less.

Metadata

Release files for modelhop 1.1.0

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.1.0
File Size Uploaded
modelhop-1.1.0.tar.gz 152.3 kB Details

Built distribution (wheel)

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

Total release size: 287.2 kB

Release files / modelhop-1.1.0.tar.gz

Download URL modelhop-1.1.0.tar.gz
Size 152.3 kB
Tags Source
SHA-256 checksum
How to use checksums
354a25fa8c7a4705c4b87cf2dc626b38acb8be7b29232527f89b9b6ec48e8495
BLAKE2b-256 checksum
How to use checksums
ff73794837eedf0ba58b9fe84e406db629b36c8ce4233ce05086e78da9c66915
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 18, 2026.

Transparency log

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

Download URL modelhop-1.1.0-py3-none-any.whl
Size 134.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
afeb4107adbca313628bdf3b790544c136cb7566056193aff2a0c1b97e743251
BLAKE2b-256 checksum
How to use checksums
f19ba785da9b77586248ed0a0aa93b5c916897b6a0f360ed18f6b8c12cb78d8d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 18, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

1.1.0 This release

2 release files

1.0.8

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