Docs/RTK Token Saver

RTK Token Saver

RTK (Result Token Kompressor) is lina-router's built-in middleware that automatically compresses tool_result content before it reaches the AI model — saving 20–40% tokens on every request.

What is a tool_result?

When AI coding tools run shell commands — git diff, grep, ls, file reads — the output gets sent back to the model as a tool_result message. These can be massive.

A single git diff on a medium-sized change can produce 3,000–8,000 tokens. Most of that verbosity doesn't add value — the model understands a compressed version just as well.

Request flow with RTK

Claude Code─── tool_result (4,200 tok) ──→
lina-router RTK─── compresses ──────────────
AI Provider─── receives (2,580 tok) ──→
Saved per request1,620 tokens (-38%)

Before vs After

RTK strips redundant whitespace, trims excessive context lines, removes binary blob representations, and normalizes repetitive patterns — while preserving all semantically important information.

Without RTK — 4,200 tokens
diff --git a/src/router/index.ts b/src/router/index.ts index 3a4f2b1..8c91d3e 100644 --- a/src/router/index.ts +++ b/src/router/index.ts @@ -1,40 +1,45 @@ -import { Provider } from './provider' +import { Provider, ProviderConfig } from './provider' import { RTK } from './rtk' ... (continues for 180 more lines)
With RTK — 2,580 tokens
diff src/router/index.ts + import ProviderConfig from './provider' + Router implements IRouter ~ providers: Provider[] (unchanged) ~ RTK integration (unchanged) [45 lines compressed, semantics preserved]
Tool outputBefore RTKAfter RTKSaved
git diff (medium PR)4,200 tok2,580 tok-38%
ls -la (large dir)800 tok480 tok-40%
grep output (50 matches)1,600 tok1,040 tok-35%
File read (500 lines)6,000 tok3,900 tok-35%

Configuration

RTK is enabled by default for all requests routed through lina-router. No configuration required.

To disable RTK (not recommended), go to Dashboard → Settings → RTK Token Saver → Off.

You can also control RTK aggressiveness (compression level) in the same settings panel. Default is "Balanced" — best savings without ever confusing the model.

Note: RTK operates transparently on the proxy layer. Your CLI tool sends normal requests — RTK intercepts and compresses tool_result blocks before forwarding to the provider.