ai-router is a python cli tool to route local models based on your local system specifications. Underneath, ai-router uses Ollama and scores/ranks installed models against prompt-derived features, then runs the prompt with the highest-ranked model.
- Loads model definitions from
src/config/models.yaml - Detects installed Ollama models via
ollama list - Builds request features from:
- prompt token count (
len(prompt.split())) - whether
git diffis non-empty - simple keyword-based capability inference
- prompt token count (
- Selects one model using capability/context/priority scoring
- Streams generation output from
ollama run <model>
- Python
- Ollama CLI available on PATH
If Ollama is missing, ai-router attempts to install it automatically using the official installer script on macOS/Linux.
uv pip install -e .Entry point:
ai-routerRoute a prompt to the best available configured model and stream output.
ai-router chat "implement a CQRS system"
ai-router chat "review this diff" --verboseOptions:
--verbose: prints selected model name before streaming
Show installed Ollama models.
ai-router modelsPull all models declared in src/config/models.yaml.
ai-router install_modelsShow routing features and selected model without running generation.
ai-router explain "refactor auth system"Basic environment report (currently installed Ollama models).
ai-router doctorCurrent capability inference in prompts is keyword-based:
security->securityrefactor->architectureimplement->coding- non-empty
git diff->repository
Model scoring currently adds:
+30per matching inferred capability+25if request is repo-aware and model hasrepository+20if prompt token count is greater than half the modelmax_context+priorityfrom model config
The highest score wins.
Configured models live in:
src/config/models.yaml
Schema:
models:
key:
name: <ollama-model-name>
provider: ollama
capabilities: [cap1, cap2]
max_context: 32768
priority: 90Only models that are both:
- present in this config, and
- currently installed in Ollama
are considered for routing.
- Capability inference is case-sensitive and rule-based.
ai-router doctoris intentionally minimal right now.- If no configured model is installed, chat reports no available model.
- A root-level
config/directory is not used by the current loader; runtime config is read fromsrc/config/models.yaml.