Knowledge Base Regulation Tracker Standards & Frameworks OSS Directory AI Incident Database Research Paper Library Case Studies Society Articles News Jobs About Charter Sign inBecome a Member

RouteLLM

Model routing and gateways

Framework for serving and evaluating LLM routers that send each query to a strong or weak model based on predicted difficulty, cutting cost without losing quality. Named in the taxonomy.

routingcost optimisation

RouteLLM: A Framework for Cost-Effective LLM Routing

By routing queries between a strong, expensive model and a weaker, cheaper model, RouteLLM minimizes costs while maintaining high-quality responses. The framework is built on preference-based routing, leveraging public datasets like Chatbot Arena to train routers that predict query difficulty and assign tasks to the most appropriate model.

The core challenge in LLM deployment lies in balancing cost and quality. Routing all queries to the most capable model ensures high performance but incurs significant expenses, while relying solely on weaker models reduces costs but may compromise response quality. RouteLLM mitigates this dilemma by dynamically routing queries based on predicted difficulty, ensuring optimal resource allocation without sacrificing output standards.

The framework supports four distinct routing strategies, each trained using preference data from Chatbot Arena and augmented with additional techniques for improved accuracy. These strategies include a similarity-weighted (SW) ranking router, a matrix factorization model, a BERT classifier, and a causal LLM classifier. Each approach evaluates queries differently but converges on the goal of minimizing strong model usage while preserving performance.

How It Works

RouteLLM operates by intercepting incoming queries and determining whether they should be processed by a strong or weak model. This decision is based on a learned threshold that balances cost and quality. Users define a cost threshold during setup, which dictates the proportion of queries routed to the strong model. For example, a threshold of 0.11593 ensures that approximately 50% of queries are directed to the stronger model, optimizing cost efficiency.

The framework integrates seamlessly with existing OpenAI clients or can be deployed as an OpenAI-compatible server. Users initialize a RouteLLM controller with specified routers, strong and weak models, and API keys. The controller then processes requests, routing them dynamically based on the configured threshold. This setup allows for easy replacement of traditional LLM clients without altering downstream applications.

Threshold calibration is a critical step in optimizing routing performance. RouteLLM provides tools to calibrate thresholds using datasets like Chatbot Arena, ensuring that the routing strategy aligns with the specific characteristics of incoming queries. For instance, calibrating for 50% strong model usage on Chatbot Arena data yields a threshold of 0.11593, which can be fine-tuned further based on real-world query distributions.

Use Cases

RouteLLM is particularly valuable in scenarios where cost efficiency is paramount without compromising response quality.

The framework’s compatibility with a wide range of models—including open-source and closed-source options—expands its applicability. Users can pair strong models like GPT-4 with weaker alternatives such as Mixtral 8x7B or Llama 3 8B, leveraging LiteLLM for broad model support. This flexibility allows organizations to adapt RouteLLM to their specific model infrastructure, whether hosted locally or via cloud providers like Anyscale, Together AI, or Amazon Bedrock.

RouteLLM’s evaluation capabilities enable users to benchmark routing strategies against established benchmarks like MT Bench, MMLU, and GSM8K. This ensures that routing decisions align with performance expectations, providing transparency and accountability in cost-saving measures. The framework’s extensibility also allows for the integration of custom routers, facilitating continuous improvement as new models and datasets emerge.

Key Features & Capabilities

  • Drop-in Replacement for OpenAI Clients: RouteLLM can replace existing OpenAI clients with minimal code changes, enabling seamless integration into existing workflows. The framework supports both direct client replacement and deployment as an OpenAI-compatible server, ensuring compatibility with third-party tools.
  • Pre-Trained Routers for Immediate Use: The framework includes pre-trained routers such as the matrix factorization (MF) router, which has demonstrated up to 85% cost reduction on MT Bench while maintaining 95% of GPT-4’s performance.
  • Cost-Effective Performance: RouteLLM achieves comparable performance to commercial routing systems like Martian and Unify AI at a fraction of the cost. For instance, routing between GPT-4 Turbo and Mixtral 8x7B yields the same quality as commercial offerings while being 40% cheaper, making it an attractive alternative for budget-conscious deployments.
  • Support for Diverse Model Pairs: The framework generalizes well across different model pairs, including combinations like Claude 3 Opus and Llama 3 8B. Routers trained on one model pair (e.g., GPT-4 and Mixtral) perform effectively on others without retraining, demonstrating robustness in adapting to varying model capabilities.
  • Data Augmentation for Improved Accuracy: RouteLLM incorporates data augmentation techniques, such as LLM-judged preference data and golden-label datasets, to enhance router performance. For example, augmenting Chatbot Arena data with LLM-judged samples improved matrix factorization router efficiency, reducing GPT-4 usage to 14% of total calls while maintaining 95% performance.
  • Extensible Evaluation Framework: The framework includes tools for evaluating routers against standard benchmarks, allowing users to compare performance across different strategies. Evaluation results are cached for efficiency, and users can override caches to recompute metrics as needed. Supported benchmarks include MT Bench, MMLU, and GSM8K, covering a broad range of LLM capabilities.
  • Threshold Calibration Tools: RouteLLM provides utilities to calibrate routing thresholds based on query distributions, ensuring optimal cost-quality trade-offs.
  • Compatibility with LiteLLM: The framework leverages LiteLLM to support chat completions from a diverse set of models, including open-source and proprietary options.

Sources

Contribute

Spot an error, or know a record we should add? Members can propose additions and submit corrections.