OmniRoute Token Saving Compression Techniques: 11 Methods Explained

OmniRoute implements a modular, plug-in compression pipeline with 11 distinct engines—ranging from rule-based truncation to neural SLM summarization—that collectively achieve 15%–95% token savings before requests reach upstream LLM providers.

OmniRoute's token saving compression techniques are engineered as a stacked, configurable pipeline that intercepts requests in the open-sse service layer. Each engine targets a specific inefficiency in prompt construction: filler text, duplication, oversized context windows, or redundant session history. The system is controlled via the x-omniroute-compression header or global settings API, with runtime selection handled by strategySelector.ts and engine metadata registered in engineCatalog.ts.

Core Compression Engines

Caveman (Lite and Full Modes)

The Caveman engine provides fast, rule-based token reduction through open-sse/services/compression/lite.ts. It handles:

  • Stop-word removal and obvious filler elimination
  • Language-pack substitutions (localized text → concise equivalents)
  • System-prompt preservation logic
  • Image-URL stripping for vision requests

The lite variant applies minimal, safe transformations; full mode extends this with aggressive abbreviation rules. Caveman runs first in most stacked pipelines because its heuristics are computationally cheap and preserve semantic intent.

RTK (Recursive Token-Killer)

RTK in open-sse/services/compression/engines/rtk/* implements multi-layer deduplication and smart truncation:

  • rtk/deduplicator.ts: Detects and removes duplicated lines across the request
  • rtk/filterLoader.ts: Loads trained filters for domain-specific trimming
  • Smart-truncation heuristics that evaluate line importance before cutting

RTK excels at collapsing repetitive prompts—common in few-shot examples or copy-pasted context blocks.

Ultra (Two-Tier Neural Compression)

The Ultra engine in open-sse/services/compression/ultra.ts implements the deepest compression:

  1. Tier 1 – Heuristic pruning (ultraHeuristic.ts): Scores token importance, drops lowest-scoring content
  2. Tier 2 – SLM routing: Rewrites prose through LLMLingua-2 for maximal density

Ultra is gated behind the ultra mode because tier-2 incurs additional latency. The heuristic tier alone typically yields 30%–50% savings.

Aggressive Truncation

open-sse/services/compression/aggressive.ts implements budget-driven hard truncation. When a request nears the provider's context limit, this engine enforces a configurable token ceiling with minimal preservation logic. Use this as a last-resort safety valve.

Headroom Management

The Headroom engines in open-sse/services/compression/engines/headroom/* maintain context-window safety margins:

These engines insert a smart-crusher that compresses content while reserving configurable token budget for model response generation.

Caching and Deduplication Systems

CCR (Context-Cache-Retrieval)

CCR in open-sse/services/compression/engines/ccr/* eliminates re-tokenization of large recurring blocks:

  • Stores seen content in persistent SQLite cache
  • Substitutes cached blocks with short references (ccr://{hash})
  • Configurable via COMPRESSION_CCR_RETRIEVAL_RAMP_FACTOR for gradual cache warm-up

CCR delivers the highest savings for applications with stable system prompts or repeated documentation context.

Session-Dedup

open-sse/services/compression/engines/session-dedup/* applies fuzzy hashing to detect near-duplicate messages within a single chat session. This catches:

  • Repeated user clarifications
  • Redundant assistant acknowledgments
  • Circular conversation patterns

Preservation and Safety Mechanisms

Prefix-Freeze and Preservation

open-sse/services/compression/prefixFreeze.ts and preservation.ts implement guaranteed-untouched zones:

  • System prompts remain uncompressed regardless of other engine settings
  • Frequently observed prefixes are identified and protected
  • Configurable via regex patterns in compressionConfigSchemas.ts

Progressive Aging

open-sse/services/compression/progressiveAging.ts dynamically reduces compression aggressiveness as conversation turns accumulate. This prevents over-truncation in long multi-turn sessions where early context carries disproportionate importance.

Configuration and Control

Output Styles

The Output Styles system in open-sse/services/compression/outputStyles/* maps user-facing modes to engine combinations:

Style Engines Activated Typical Savings
terse Caveman lite only 15%–25%
lite Caveman full 25%–40%
full Caveman → RTK 40%–60%
ultra Caveman → RTK → Ultra tier-1 → Ultra tier-2 60%–95%

Adaptive Compression

open-sse/services/compression/adaptiveCompression/* implements auto-tuned budget selection. The engine:

  1. Reads model context window from provider metadata
  2. Calculates current usage vs. safety margin
  3. Selects the cheapest engine stack satisfying the budget

This eliminates manual mode selection for most requests.

Using Compression in Practice

Per-Request Header Control

Enable compression for individual requests via the x-omniroute-compression header:

import fetch from "node-fetch";

const response = await fetch("https://my-omniroute-host/v1/chat/completions", {
  method: "POST",
  headers: {
    "Content-Type": "application/json",
    "x-omniroute-compression": "stacked", // or: off, lite, standard, aggressive, ultra, rtk
  },
  body: JSON.stringify({
    model: "gpt-4o",
    messages: [{ role: "user", content: largePrompt }],
  }),
});

Previewing Compression Plans

Validate savings before sending to the provider:

curl -X POST https://my-omniroute-host/api/compression/preview \
  -H "Content-Type: application/json" \
  -d '{
        "mode": "stacked",
        "messages": [{"role":"user","content":"<very long text>"}]
      }'

The response from src/app/api/compression/preview.ts includes transformed messages, techniques applied, and estimated tokens saved.

Global Configuration

Set default compression via the settings API:

await fetch("https://my-omniroute-host/api/settings/compression", {
  method: "PUT",
  headers: { "Content-Type": "application/json" },
  body: JSON.stringify({ mode: "rtk", enabled: true })
});

Schema validation occurs in src/shared/validation/compressionConfigSchemas.ts.

Monitoring and Analytics

Each engine records statistics via open-sse/services/compression/compressionAnalyticsWrite.ts. The monitoring UI displays:

  • Per-engine token savings percentages
  • Pipeline composition frequencies
  • Compression latency overhead

Benchmark data is validated through compression-savings.test.ts in the golden-set test suite.

Summary

  • OmniRoute token saving compression operates as a modular, stackable pipeline in open-sse/services/compression/
  • 11 core engines address distinct inefficiencies: rule-based truncation (Caveman), deduplication (RTK, Session-Dedup), neural summarization (Ultra), caching (CCR), and safety mechanisms (Headroom, Progressive Aging, Prefix-Freeze)
  • Configuration flexibility via headers, global settings, and adaptive auto-selection
  • 15%–95% token savings achievable depending on mode and content type
  • Observability built-in through analytics writes and preview endpoints

Frequently Asked Questions

How do I enable the highest possible token compression in OmniRoute?

Set x-omniroute-compression: ultra in your request headers. This activates the full stacked pipeline: Caveman → RTK → Ultra heuristic → Ultra SLM tier. Expect 60%–95% savings with additional latency from the neural summarization step. For latency-sensitive applications, use stacked mode which omits the SLM tier.

What is the difference between RTK and Session-Dedup engines?

RTK (open-sse/services/compression/engines/rtk/*) operates within a single request, removing duplicated lines and trimming blocks through importance scoring. Session-Dedup (open-sse/services/compression/engines/session-dedup/*) maintains state across conversation turns, using fuzzy hashing to eliminate near-duplicate messages that accumulate in multi-turn chats. They complement each other—RTK for immediate redundancy, Session-Dedup for conversational drift.

Does OmniRoute compression affect system prompts?

No. The Prefix-Freeze engine (open-sse/services/compression/prefixFreeze.ts) and Preservation system guarantee that system prompts and configured prefix patterns remain untouched regardless of compression mode. This is enforced at the pipeline level before any mutating engine executes.

How does CCR caching work across deployments?

CCR stores compressed content blocks in a persistent SQLite database with content-addressable hashing. When a block reappears—whether in the same session, different session, or after application restart—it is substituted with a ccr://{hash} reference. The COMPRESSION_CCR_RETRIEVAL_RAMP_FACTOR environment variable controls how aggressively the cache is consulted during warm-up periods.

Have a question about this repo?

These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:

Share the following with your agent to get started:
curl -s "https://instagit.com/install.md"

Works with
Claude Codex Cursor VS Code OpenClaw Any MCP Client

Maintain an open-source project? Get it listed too →