R2-Router introduces reasoning into LLM routing. Instead of treating each LLM as a fixed quality-cost point, R2-Router reasons about how quality varies with output length, jointly selecting the best LLM and token budget. This transforms routing from selecting among points to searching over quality-cost curves, achieving state-of-the-art performance at 4-5x lower cost.
Under review at ICML 2026.
Existing LLM routers assume each model has a single fixed quality-cost profile per query. This causes them to exclude powerful LLMs when estimated cost exceeds the budget, missing the opportunity that these LLMs could still deliver high quality with shorter outputs.
R2-Router addresses this by:
This enables R2-Router to discover that a powerful LLM with constrained output can outperform a weaker LLM at comparable cost -- efficient configurations invisible to prior methods.
R2-Bench is the first LLM routing dataset capturing behavior across diverse output length budgets:
R2-Bench raises the Oracle upper bound by 15% in AUDC compared to prior single-response datasets.
git clone https://github.com/jqxue1999/router.git
cd router
# Using uv (recommended)
uv sync
# Or using pip
pip install -e .
r2-router/
├── scripts/ # RouterArena pipeline
│ ├── category_config.py # Shared config (models, paths, categories)
│ ├── route_and_eval.py # Route queries + evaluate against sweep GT
│ ├── route_knn_export.py # Export RouterArena submission JSON (Global KNN)
│ ├── sweep_lambda_global_knn.py # Lambda sweep with Global KNN routing
│ ├── train_category_predictors.py # Train KNN quality + token predictors
│ ├── train_category_classifier.py # Train SVM category classifier
│ ├── build_category_training_data.py # Build training_data.pkl from sweep files
│ ├── inference_budget_sweep.py # Budget sweep inference (vLLM)
│ ├── inference_routerarena.py # vLLM/API inference engine
│ ├── eval_sweep.py # Evaluate sweep files (writes accuracy/cost)
│ └── *.sbatch # SLURM job scripts
├── main/ # IID evaluation pipeline (R2-Bench)
│ ├── r2/ # R2-Router predictors (sklearn)
│ ├── baselines/ # CARROT, IRT baselines
│ ├── shared/ # DatasetManager, utils
│ ├── evaluation/ # Compare methods
│ └── run_experiment.sh # Automated pipeline
├── routerarena_submission/ # RouterArena submission files
├── data_collection/ # R2-Bench data pipeline
├── ood_evaluation/ # Out-of-distribution evaluation
├── unirouter/ # UniRouter integration
└── demo/ # Interactive web demo (Gradio)
# Route and evaluate locally (against sweep ground truth)
.venv/bin/python scripts/route_and_eval.py --lambda_val 0.98 --shrinkage_k 3.0
# Train KNN predictors
sbatch scripts/train_predictors.sbatch
# Export submission for RouterArena
.venv/bin/python scripts/route_knn_export.py \
--models 235b ministral-3b gemini-flash --lambda_val 0.85 \
--export routerarena_submission/submission.json
bash main/run_experiment.sh
Following the evaluation protocol from UniRouter (Jitkrittum et al., 2025):
R2-Router achieves comparable quality at 4-5x lower cost compared to reactive baselines:
| Method | AUDC | QNC | Peak Quality |
|---|---|---|---|
| MIRT | 0.74 | 0.78 | 0.81 |
| CARROT-L | 0.77 | 0.66 | 0.80 |
| R2-Router | 0.80 | 0.29 | 0.81 |
If you use this code or R2-Bench, please cite:
@inproceedings{r2router2026,
title={R2-Router: A New Paradigm for LLM Routing with Reasoning},
author={Anonymous},
booktitle={International Conference on Machine Learning (ICML)},
year={2026}
}
MIT License
3 commits
Python
87.0%
Shell
13.0%
R2-Router introduces reasoning into LLM routing. Instead of treating each LLM as a fixed quality-cost point, R2-Router reasons about how quality varies with output length, jointly selecting the best LLM and token budget. This transforms routing from selecting among points to searching over quality-cost curves, achieving state-of-the-art performance at 4-5x lower cost.
Under review at ICML 2026.
Existing LLM routers assume each model has a single fixed quality-cost profile per query. This causes them to exclude powerful LLMs when estimated cost exceeds the budget, missing the opportunity that these LLMs could still deliver high quality with shorter outputs.
R2-Router addresses this by:
This enables R2-Router to discover that a powerful LLM with constrained output can outperform a weaker LLM at comparable cost -- efficient configurations invisible to prior methods.
R2-Bench is the first LLM routing dataset capturing behavior across diverse output length budgets:
R2-Bench raises the Oracle upper bound by 15% in AUDC compared to prior single-response datasets.
git clone https://github.com/jqxue1999/router.git
cd router
# Using uv (recommended)
uv sync
# Or using pip
pip install -e .
r2-router/
├── scripts/ # RouterArena pipeline
│ ├── category_config.py # Shared config (models, paths, categories)
│ ├── route_and_eval.py # Route queries + evaluate against sweep GT
│ ├── route_knn_export.py # Export RouterArena submission JSON (Global KNN)
│ ├── sweep_lambda_global_knn.py # Lambda sweep with Global KNN routing
│ ├── train_category_predictors.py # Train KNN quality + token predictors
│ ├── train_category_classifier.py # Train SVM category classifier
│ ├── build_category_training_data.py # Build training_data.pkl from sweep files
│ ├── inference_budget_sweep.py # Budget sweep inference (vLLM)
│ ├── inference_routerarena.py # vLLM/API inference engine
│ ├── eval_sweep.py # Evaluate sweep files (writes accuracy/cost)
│ └── *.sbatch # SLURM job scripts
├── main/ # IID evaluation pipeline (R2-Bench)
│ ├── r2/ # R2-Router predictors (sklearn)
│ ├── baselines/ # CARROT, IRT baselines
│ ├── shared/ # DatasetManager, utils
│ ├── evaluation/ # Compare methods
│ └── run_experiment.sh # Automated pipeline
├── routerarena_submission/ # RouterArena submission files
├── data_collection/ # R2-Bench data pipeline
├── ood_evaluation/ # Out-of-distribution evaluation
├── unirouter/ # UniRouter integration
└── demo/ # Interactive web demo (Gradio)
# Route and evaluate locally (against sweep ground truth)
.venv/bin/python scripts/route_and_eval.py --lambda_val 0.98 --shrinkage_k 3.0
# Train KNN predictors
sbatch scripts/train_predictors.sbatch
# Export submission for RouterArena
.venv/bin/python scripts/route_knn_export.py \
--models 235b ministral-3b gemini-flash --lambda_val 0.85 \
--export routerarena_submission/submission.json
bash main/run_experiment.sh
Following the evaluation protocol from UniRouter (Jitkrittum et al., 2025):
R2-Router achieves comparable quality at 4-5x lower cost compared to reactive baselines:
| Method | AUDC | QNC | Peak Quality |
|---|---|---|---|
| MIRT | 0.74 | 0.78 | 0.81 |
| CARROT-L | 0.77 | 0.66 | 0.80 |
| R2-Router | 0.80 | 0.29 | 0.81 |
If you use this code or R2-Bench, please cite:
@inproceedings{r2router2026,
title={R2-Router: A New Paradigm for LLM Routing with Reasoning},
author={Anonymous},
booktitle={International Conference on Machine Learning (ICML)},
year={2026}
}
MIT License
3 commits
Python
87.0%
Shell
13.0%