# LLMRouter

> Open-source library and CLI for cost-aware LLM routing with 16+ router algorithms

- Category: Evaluation & Production Ops / Gateways & Routing
- Language: Python
- Licence: MIT
- Repository: https://github.com/ulab-uiuc/LLMRouter
- Canonical page: https://ai-tldr.dev/tools/llmrouter/

## In short

LLMRouter is an open-source Python library and command-line tool that picks the most suitable language model for each incoming query. It sits in the Gateways & Routing category of the Evaluation & Production Ops tools and is open-source, written in Python and licensed MIT. To get started: install from PyPI.

## Overview

LLMRouter is an open-source Python library and command-line tool that picks the most suitable language model for each incoming query. Instead of sending every request to one model, it routes based on task complexity, cost, and performance, so you can use cheaper models for easy queries and stronger ones where they're needed.

It ships with more than 16 routing models, grouped into single-round, multi-round, agentic, and personalized routers. These cover strategies such as KNN, SVM, MLP, matrix factorization, Elo rating, graph-based, and BERT-based routing. There's also a data-generation pipeline that builds training data from 11 benchmark datasets with automatic API calling and evaluation.

As an LLM gateway, it sits between your application and several model providers. A unified `llmrouter` CLI handles training, inference, and an interactive Gradio chat UI, and a plugin workflow lets you add your own routers and tasks. It's aimed at developers and researchers who want to compare routing strategies or cut inference cost without locking into a single model.

## What it does

- Routes each query to a suitable model based on task complexity, cost, and performance
- Over 16 router models across single-round, multi-round, agentic, and personalized categories
- Unified `llmrouter` CLI for training, inference, and interactive chat
- Gradio-based chat UI for trying routers interactively
- Data-generation pipeline using 11 benchmark datasets with automatic API calling and evaluation
- Plugin workflow for building custom routers and adding your own tasks

## Getting started

LLMRouter is published on PyPI as `llmrouter-lib` and exposes a unified `llmrouter` CLI. Install it, then use the CLI to train a router, run inference, or open the interactive chat UI.

1. Install from PyPI

   Install the library with pip. LLMRouter targets Python 3.10.

```bash
pip install llmrouter-lib
```

2. Explore the CLI

   After installing, the `llmrouter` command is available for training, inference, and the interactive chat interface. Run it with --help to see available subcommands.

```bash
llmrouter --help
```

3. Follow the docs for routing config

   The training and inference commands depend on your dataset, chosen router (for example knnrouter or mlprouter), and provider keys, so follow the project's online docs and per-router tutorials for exact arguments.

## When to use it

- Cut LLM inference cost by sending simple queries to cheaper models and hard ones to stronger models
- Benchmark and compare different routing strategies on standard datasets before production
- Add a custom router or task for a domain-specific routing policy via the plugin workflow
- Stand up an interactive chat UI to test how a trained router behaves across queries
