model-router
Model Router — 비용 인식 다중 LLM 라우팅: 무료 우선, 유료 폴백 체인
모든 작업을 최적의 모델로 자동 라우팅 — 무료 제공자를 먼저 시도하고, 유료 제공자를 폴백으로 사용합니다.
🎯 Model Router를 사용해야 하는 이유?
대부분의 LLM 통합 코드는 단일 모델을 하드코딩하거나 단일 API 제공자에 의존합니다. 이는 다음과 같은 문제를 초래합니다:
❌ 비용 과다: 모든 요청(사소한 작업까지)이 유료 frontier 모델로 전송됩니다.
❌ 취약성: 하나의 제공자가 중단되면 전체 시스템이 마비됩니다.
❌ 유연성 부족: 작업 난이도에 맞게 모델 성능을 매칭할 방법이 없습니다.
Model Router는 의존성이 적고 간단한 설계로 세 가지 문제를 모두 해결합니다:
✅ 작업 난이도 분류: 키워드 + 콘텐츠 길이 휴리스틱(비용 제로, LLM 미사용)을 통해 5단계(
vision/long/complex/medium/simple)로 분류합니다.✅ 무료 우선 폴백 체인: 각 라우팅 레벨은 순서가 지정된 후보 체인을 정의합니다. 무료 제공자(Zhipu, SiliconFlow, OpenRouter 무료 모델)를 먼저 시도하고, 실패 시 자동으로 다음 후보(최종적으로 유료 DeepSeek/Qwen/GLM/Kimi)로 전환합니다.
✅ 타사 의존성 제로: 핵심 라이브러리는
requests만 필요합니다. MCP 서버는 순수 stdlib(stdio를 통한 JSON-RPC 2.0)로 구성됩니다.✅ 다중 인터페이스: Python API · CLI · MCP 서버(모든 MCP 클라이언트: Claude, Qoder, Cursor 등) · 파일 감시 데몬
🏗 아키텍처
┌─────────────────────────────────────────────┐
│ router_core.py │
│ │
task_desc ──▶│ classify_task() → 5 difficulty levels │
content ──▶│ _get_candidates() → ordered provider chain│
image ──────▶│ route_and_call() → free-first, fallback │
│ │
└──────────────┬──────────────────────────────┘
│
┌────────────────┼───────────────────┐
▼ ▼ ▼
auto_router.py mcp_server.py Python API
(CLI + daemon) (MCP tools) (import router_core)라우팅 레벨
레벨 | 트리거 조건 | 일반적인 모델 |
| 이미지/스크린샷/OCR | Qwen-VL, GLM-4V |
| 2000자 이상 콘텐츠, 전체 문서 | 128K 컨텍스트 모델 |
| 분석/코드/데이터/통계/추론 | DeepSeek, Qwen3-32B |
| 글쓰기/번역/다듬기 | GLM, Qwen |
| 일상 대화 / 빠른 질의 | 소형 무료 모델 |
폴백 의미: 후보는 순서대로 시도됩니다. 응답에는 tier(무료/유료), attempts, fallback_used, 각 제공자의 errors 정보가 포함되어 전체 관측 가능성을 제공합니다.
🚀 빠른 시작
# 1. Install (only requests is required)
pip install requests
# 2. Configure
cp config.example.json config.json
# → fill in your API keys
# 3. CLI — analyze only (zero cost, no model call)
python router_core.py analyze "分析这份气象数据"
# 4. CLI — route and call
python router_core.py call "翻译以下段落" --content "Hello world" --system "你是专业翻译"
# 5. Python API
from router_core import route_and_call, analyze_task
result = analyze_task("写一份论文摘要", content_len=300)
print(result["primary"]) # first candidate
print(result["candidates"]) # full fallback chain
text = route_and_call("总结要点", "long text...")["content"]🖥 MCP 서버 (모든 MCP 클라이언트용)
python mcp_server.py도구 | 설명 |
| 자동 라우팅 + 호출 (무료 우선, 실패 시 폴백) |
| 난이도 분석 + 후보 체인 반환 (비용 제로) |
| 구성된 모든 제공자, 모델 및 체인 나열 |
MCP 클라이언트에 등록 (예: Claude Desktop claude_desktop_config.json):
{
"mcpServers": {
"model-router": {
"command": "python",
"args": ["/path/to/model-router/mcp_server.py"],
"env": {"PYTHONIOENCODING": "utf-8"}
}
}
}⏱ 작업 트리거 데몬 (파일 감시 모드)
# One-shot
python auto_router.py "任务描述" -c "内容" --image photo.png
# Daemon: drop task files into inbox/, results appear in outbox/
python auto_router.py --watch --dir ./tasks🔧 구성
config.json 구조 (예제 파일 config.example.json 참조):
providers:
tier(free/paid)와 선택적enabled: false가 있는 OpenAI 호환 엔드포인트routing: 각 레벨별 순서가 지정된
candidates체인 — 무료 우선, 유료는 안전망 역할levels: 각 레벨에 대한 사람이 읽을 수 있는 설명
제공자를 자유롭게 추가하거나 제거할 수 있습니다. 라우터는 완전히 데이터 기반으로 작동합니다.
📄 라이선스
MIT — 개인 및 상업적 용도로 무료입니다. LICENSE 파일을 참조하십시오.
실제 비용 최적화에서 영감을 받았습니다. 일상 작업의 약 90%는 무료 등급 모델로 처리할 수 있으며, 어려운 작업은 자동 폴백을 통해 최첨단 모델 품질을 보장합니다.
This server cannot be installed
Maintenance
Resources
Unclaimed servers have limited discoverability.
Looking for Admin?
If you are the server author, to access and configure the admin panel.
Related MCP Connectors
Hosted MCP server for LLM cost estimation, model comparison, and budget-aware routing.
Agent Cost Allocator MCP — multi-tenant LLM cost attribution for chargeback billing. Companion to
MCP server providing access to the Scorecard API to evaluate and optimize LLM systems.
Latest Blog Posts
- Who's Calling? MCP Hosts Are an Identity Blind Spot (And the Spec Knows It)By Om-Shree-0709 on .mcpAgent IdentityOAuth 2.1
- Your AI Chatbot Just Exposed Your CEO's Salary to an InternBy Om-Shree-0709 on .Agent IdentityMCP SecurityOAuth Delegation
- Why MCP Servers Need Execution Sandboxing (And Why Your Current Stack Isn't Enough)By Om-Shree-0709 on .Agentic AiPrompt InjectionWebAssembly
MCP directory API
We provide all the information about MCP servers via our MCP API.
curl -X GET 'https://glama.ai/api/mcp/v1/servers/yaowanxiang/model-router'
If you have feedback or need assistance with the MCP directory API, please join our Discord server