█

AI/TLDR

Buy me a coffee
Buy me a coffee

LLMRouter

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

Gateways & RoutingOpen source
Language
Python
License
MIT
$pip install llmrouter-lib
IN SHORT

What is LLMRouter?

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.

Install from PyPI

Install the library with pip. LLMRouter targets Python 3.10.

bashbash
pip install llmrouter-lib

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.

bashbash
llmrouter --help

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.

Commands and code are distilled from the project's own documentation — always check the official repo for the latest.

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

How LLMRouter compares

LLMRouter alongside other open-source gateways & routing tools AI/TLDR tracks, ranked by GitHub stars.

ToolStarsWhat it does
OmniRoute★ 91.4kA local-first AI gateway that fronts hundreds of model providers with one OpenAI-compatible endpoint, quota-aware auto-fallback, many routing strategies and prompt compression.
Free Claude Code★ 74.7kA local proxy that points Claude Code, Codex, Pi, OpenCode, Cline and other agent CLIs at 50 free, paid, subscription or local model providers, with automatic failover and an admin UI.
LiteLLM★ 64.2kA Python SDK and proxy server that gives one OpenAI-compatible API to 100+ LLM providers, with cost tracking, budgets, fallbacks, rate limiting, and an admin UI.
Kong Gateway★ 44.4kA Lua/NGINX API gateway whose AI Gateway plugins put one universal endpoint in front of OpenAI, Anthropic, Gemini, Bedrock and other providers, with semantic routing, caching and MCP traffic governance.
magpie★ 43.7kMenu bar app and local gateway that lets Claude Code, Codex, Gemini CLI and dozens of other coding agents run on any provider's model, with routing groups that fail over across accounts when a quota runs out.
9Router★ 33kLocal OpenAI-compatible router for coding CLIs that tracks per-provider quota, falls back from subscription to cheap to free models, and compresses tool results to cut tokens.
Experiential★ 20.1kAn open-source gateway that puts hosted, BYOK, local and custom models behind one OpenAI-compatible API, with per-identity model and spend limits and routers fitted from your own traces.
LLMRouter★ 3.1kOpen-source library and CLI for cost-aware LLM routing with 16+ router algorithms