Cost-Aware Contrastive Routing for LLMs
Reza Shirkavand, Shangqian Gao, Peiran Yu, Heng Huang
TL;DR
CSCR tackles the problem of cost-aware routing among diverse LLM pools by learning a unified embedding space that jointly encodes prompt semantics, model capability, and per-model cost. It introduces two lightweight descriptors, logit footprints for open-weight LLMs and perplexity fingerprints for API-based models, and trains a contrastive InfoNCE objective augmented with cost bands to prioritize cheaper yet accurate experts. Inference reduces to a fast k-NN lookup over FAISS, enabling microsecond routing while avoiding retraining when the pool changes. Across three benchmarks, CSCR improves the accuracy–cost Pareto frontier and generalizes robustly to unseen models and out-of-distribution prompts, illustrating practical gains for scalable, economical deployment of multi-LLM systems.
Abstract
We study cost-aware routing for large language models across diverse and dynamic pools of models. Existing approaches often overlook prompt-specific context, rely on expensive model profiling, assume a fixed set of experts, or use inefficient trial-and-error strategies. We introduce Cost-Spectrum Contrastive Routing (CSCR), a lightweight framework that maps both prompts and models into a shared embedding space to enable fast, cost-sensitive selection. CSCR uses compact, fast-to-compute logit footprints for open-source models and perplexity fingerprints for black-box APIs. A contrastive encoder is trained to favor the cheapest accurate expert within adaptive cost bands. At inference time, routing reduces to a single k-NN lookup via a FAISS index, requiring no retraining when the expert pool changes and enabling microsecond latency. Across multiple benchmarks, CSCR consistently outperforms baselines, improving the accuracy-cost tradeoff by up to 25%, while generalizing robustly to unseen LLMs and out-of-distribution prompts.
