跪拜 Guibai
← All articles
Open Source · Artificial Intelligence

Three Open-Source Levers to Cut LLM Costs: Task Routing, Instruction Optimization, and Consumption Control

By 掘金安东尼 ·
Read original on juejin.cn ↗ Google Translate ↗ Alt translation

Most of the savings happen before any model swap: enabling prefix caching, compressing context, and static routing are cheap, revertable moves that can cut a large share of context tokens. The hard part is attribution and regression testing, and the open-source maintenance landscape is shifting under long-tail projects, so tool selection needs an ownership check.

Summary

RouteLLM (UC Berkeley, ICLR 2025) is the reference for learned routing: a lightweight classifier decides whether a request needs a strong model, and on benchmarks it cuts up to 85% of cost while holding 95% of GPT-4 quality. But it only does strong/weak binary routing, its repo stopped updating in August 2024, and production savings depend on the share of simple requests. LiteLLM remains the active gateway for rule-based routing and budget caps; the two are commonly stacked as gateway plus per-request router.

Prompt optimization has become a compile step. DSPy's optimizer ladder runs from LabeledFewShot and BootstrapFewShot up to MIPROv2 and GEPA, where instructions and few-shot examples are searched as parameters; a single compile can cost a few hundred dollars in LM calls, so it only pays off for fixed, reusable tasks. Microsoft's PromptWizard is lighter, iterating on one prompt with an LLM in about 20-30 minutes per dataset.

On the consumption side, vendor prefix caching is the zero-rewrite baseline, semantic caching can hit 25%-60% on repeated traffic, and LLMLingua claims up to 20x compression, though compression breaks prefix caches. Context hygiene, like summarizing history and pruning RAG results, cuts 40%-75% of context tokens with no new dependency. The bill is structurally call count times model price times token volume, so observability is the first move: without per-call attribution, no optimization is measurable. For a small text-generation site, the practical sequence is: observe two weeks, turn on caching, do context hygiene, add static routing, and only then consider learned routing and prompt compilers, with a 100-item golden set as a quality gate.

Takeaways
— RouteLLM benchmarks: up to 85% cost cut on MT Bench while keeping 95% of GPT-4 quality; at that quality bar, about 45% savings on MMLU and 35% on GSM8K.
— RouteLLM trains on roughly 80k Chatbot Arena human preferences, 1,500 MMLU comparison samples, and 120k GPT-4-as-judge samples (about $700).
— RouteLLM transfers across strong/weak model pairs with only a 2-3 percentage point PGR drop, because the router learns problem difficulty rather than a specific model pair.
— RouteLLM is a frozen research prototype: its GitHub repo last had substantive updates in August 2024, so production users must fix bugs themselves.
— DSPy's optimizer ladder starts with LabeledFewShot (zero LM calls) and BootstrapFewShot, then MIPROv2 and GEPA; GEPA paper reports +12.2 points vs MIPROv2's +5.6 on GPT-4.1 Mini, with prompts up to 9.2x shorter and about 35x fewer rollouts than RL.
— A single MIPROv2 or GEPA compile can cost a few hundred dollars in LM calls, so it only pays off for fixed, reusable tasks with a computable metric.
— Microsoft PromptWizard iterates on one prompt with an LLM, claims 45 tasks and about 20-30 minutes per dataset, and shines in few-shot and small-model scenarios.
— Semantic caching can hit 25%-60% on repetitive traffic; GPTCache's last formal release was August 2024, so maintenance is questionable.
— LLMLingua claims up to 20x prompt compression, but rewriting prompts invalidates prefix caches, and aggressive compression drifts more on generative tasks than classification.
— Context hygiene (summarize conversation history, prune RAG to 2-3 passages, compress tool output) cuts 40%-75% of context tokens without adding a dependency.
— Langfuse merged into ClickHouse in January 2026 and stayed open-source; Helicone merged into Mintlify in March 2026 and moved to maintenance mode.
— The recommended sequence is observe for two weeks, enable prefix caching, do context hygiene, add static tiered routing, then learned routing only if simple-request share is high and you have a labeled eval set; after each change, run a golden-set regression of about 100 labeled requests and roll back if quality falls below 95% of baseline.
Conclusions

RouteLLM's transfer result is the least-appreciated number: the router learns difficulty features, not the specific strong/weak pair, so model swaps cost only 2-3 PGR points.

Because the three levers multiply in the bill equation, optimizing one reduces the others' returns; teams should start on whichever term is largest rather than chasing the newest tool.

Prompt compilers only pay off when a task has a computable metric and long-term reuse; a one-off task cannot amortize a few hundred dollars of compile cost, which is why static rules and context hygiene deliver most savings for most teams.

Compression and prefix caching are in direct tension: rewriting prompts invalidates the cached prefix, so stable system prompts should stay byte-identical while volatile content goes through compression or summarization.

Project ownership now shapes tool choice: RouteLLM is a frozen research prototype, GPTCache stopped releasing, Helicone moved to maintenance after acquisition, so production users need a maintenance plan before depending on any long-tail OSS component.

Concepts & terms
PGR
Performance Gap Recovery: the share of the quality gap between a strong and weak model that a routing scheme recovers. 95% is a common go-live threshold.
CPT
The minimum percentage of requests that must be sent to the strong model to achieve a target PGR. Lower CPT means more savings.
Semantic caching
Caching responses by embedding similarity: if a new request is semantically close to a past one, return the cached answer and skip the model call. Hit rates in this source range from 25% to 60% on repetitive traffic.
Prompt compilation
Using optimizers to search over instructions and few-shot examples as parameters, producing a reusable artifact. DSPy's ladder and GEPA are examples; compilation cost can be a few hundred dollars, so it pays off only with long-term reuse.
GEPA
A reflective evolution optimizer in DSPy that reads metric feedback and execution traces, has an LLM diagnose failures and propose new instructions, and keeps multiple candidates on the Pareto front. The paper reports gains over MIPROv2 with fewer rollouts.
Source: juejin.cn ↗ Google Translate ↗ Backup ↗