What is RouteLLM?
RouteLLM is a framework from LMSYS for serving and evaluating LLM routers. It looks at each incoming query and decides whether to send it to a stronger, more expensive model or to a cheaper, weaker one. It sits in the Gateways & Routing category of the Evaluation & Production Ops tools and is open-source, written in Python.
Overview
RouteLLM is a framework from LMSYS for serving and evaluating LLM routers. It looks at each incoming query and decides whether to send it to a stronger, more expensive model or to a cheaper, weaker one. The goal is to keep response quality high while spending less on inference.
It works as a drop-in replacement for the OpenAI client, or you can launch an OpenAI-compatible server that any existing OpenAI client can talk to. Trained routers ship out of the box, and LMSYS reports they can reduce costs by up to 85% while keeping about 95% of GPT-4 performance on benchmarks like MT Bench. Model calls go through LiteLLM, so you can pair models from many open and closed providers.
It fits in the LLM gateway and routing space: instead of hard-coding one model for every request, you put RouteLLM in front of two models and let a cost threshold control the cost-quality tradeoff. It is aimed at teams running production LLM traffic who want to trim spend without rewriting their app.
What it does
- Drop-in replacement for the OpenAI client, plus an OpenAI-compatible server mode that works with existing OpenAI clients.
- Trained routers (such as the matrix-factorization `mf` router) included out of the box, no training required to start.
- A per-request cost threshold that tunes the tradeoff between cost and response quality.
- Threshold calibration tool that sets the cutoff for a target percentage of strong-model calls using Chatbot Arena data.
- Wide model support through LiteLLM, including any OpenAI-compatible endpoint via the `openai/` prefix with `--base-url` and `--api-key`.
- Extensible benchmarking so you can add new routers and compare them across benchmarks.
Getting started
Install RouteLLM from PyPI, then swap your OpenAI client for the RouteLLM controller and route between a strong and weak model.
Install
Install from PyPI with the serve and eval extras.
pip install "routellm[serve,eval]"Initialize the controller
Replace your OpenAI client with the RouteLLM controller using the `mf` router, and set a strong model and a weak model. Set the API keys for whichever providers you use.
import os
from routellm.controller import Controller
os.environ["OPENAI_API_KEY"] = "sk-XXXXXX"
# Replace with your model provider, we use Anyscale's Mixtral here.
os.environ["ANYSCALE_API_KEY"] = "esecret_XXXXXX"
client = Controller(
routers=["mf"],
strong_model="gpt-4-1106-preview",
weak_model="anyscale/mistralai/Mixtral-8x7B-Instruct-v0.1",
)Calibrate a cost threshold
Pick a threshold for the share of queries you want sent to the strong model. For example, calibrate for 50% GPT-4 calls using Chatbot Arena data.
python -m routellm.calibrate_threshold --routers mf --strong-model-pct 0.5 --config config.example.yamlRoute completions
Set the `model` field to the router and threshold, then call chat completions as usual. RouteLLM routes each request between the strong and weak model.
response = client.chat.completions.create(
# Use the MF router with a cost threshold of 0.11593
model="router-mf-0.11593",
messages=[
{"role": "user", "content": "Hello!"}
]
)Commands and code are distilled from the project's own documentation — always check the official repo for the latest.
When to use it
- Cut inference spend on an existing OpenAI-based app by routing only the hard queries to a top-tier model while sending the rest to a cheaper one.
- Stand up an OpenAI-compatible routing proxy in front of two models so multiple services can share the same cost-aware endpoint.
- Tune the strong-model call rate for your own traffic by calibrating the cost threshold against real query patterns.
- Evaluate and compare different routers across benchmarks before choosing one for production.
How RouteLLM compares
RouteLLM alongside other open-source gateways & routing tools AI/TLDR tracks, ranked by GitHub stars.
| Tool | Stars | What it does |
|---|---|---|
| OmniRoute | ★ 91.4k | A 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.7k | A 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.2k | A 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.4k | A 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.7k | Menu 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 | ★ 33k | Local 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.1k | An 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. |
| RouteLLM | ★ 5.7k | Route easy queries to cheap models and hard ones to strong models to cut LLM cost |

