> ## Documentation Index
> Fetch the complete documentation index at: https://www.edgee.ai/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Token Compression V2

> Token compression is the surgical removal of redundancy, not summarization. Edgee treats it in two distinct layers, input and output.

Token compression reduces the number of tokens sent to and received from the LLM, without losing information from the model's perspective. Compression is the surgical removal of redundancy. Not summarization.

## Two layers

The two-layer taxonomy is the non-negotiable foundation. Every strategy in this page belongs to exactly one of them.

* **Input compression**: \~99% of total token volume, \~90% of the cost. What enters the context window: system prompts, tool results, codebase context, conversation history, MCP tool definitions.
* **Output compression**: \~1% of total volume but 10% of the cost. What the model generates: filler, repetitive scaffolding, polite preambles, over-explanation, markdown overhead.

Agentic workloads consume 5–30× more tokens per task than chatbot workloads, and approximately 40% of those tokens are redundant. Compression targets that redundant share.

## The three compression strategies

Edgee ships three named compression strategies, toggleable independently. Compression V2 sharpens `tool_result_trimming`, adds `tool_surface_reduction` as a new Layer 1 technique, and adds `output_brevity` as a new Layer 2 technique.

| Compression            | Layer  | Status            | Session reduction |
| ---------------------- | ------ | ----------------- | ----------------- |
| Tool Result Trimming   | Input  | Improved in V2    | **−10%**          |
| Tool Surface Reduction | Input  | New in V2 (alpha) | **−10%**          |
| Output Brevity         | Output | New in V2         | **−30%**          |

Figures above are illustrative, on a mixed suite of coding-agent workflows (18,420 → 9,210 tokens with all three on, a **−50%** reduction) — not a measured benchmark. Your mileage may vary. Sourced customer-traffic averages are called out per technique below.

## Tool Result Trimming

Filters `tool_result` messages before they reach the model. Strips:

* Boilerplate framing
* Pagination markers
* ANSI escape sequences
* Repeated headers
* Verbose JSON wrappers

What it targets in a typical coding-agent session:

* **File contents** — output from Read tool and file system operations.
* **Grep and search outputs** — code search, ripgrep, similar tools.
* **Shell command output** — stdout/stderr from Bash and terminal commands.
* **API responses** — large JSON or text payloads returned by tool calls.
* **Database query results** — rows and records returned from tool-executed queries.

User messages and assistant turns are not modified.

**Lossiness.** Lossless on `tool_result` payloads — the model receives the same technical content, with redundant framing removed.

**Status.** Improved in V2 — trims harder while staying lossless on code tasks (a 980-token directory listing becomes a dense 340-token one the model reads just as well).

**Illustrative session share.** −10% (see table above). **Customer-traffic average (rolling 30 days).** `tool_result_trimming` reduces token costs by **19%** on average — a different baseline, not additive with the session figure.

Initially based on [`rtk-ai/rtk`](https://github.com/rtk-ai/rtk), we built our tool result compression strategy directly into the Edgee Rust gateway, so users don't need a separate binary in their pipeline.

## Tool Surface Reduction

Coding agents connect multiple MCP servers, each exposing its own set of tools. The agent sends the full tool list to the model on every request, even when only one or two MCP servers are relevant. This bloats context and drives up cost.

**How it works:**

Edgee creates a **virtual MCP server** that the model sees. Instead of the full tool list, the model talks to the virtual MCP. The virtual MCP classifies the user's task and searches for the correct real MCP server to use. It sends the result back to the client, which then executes the real MCP server.

The result is a **tool-aware gateway**:

* The IDE still exposes all MCP servers — nothing changes for the developer's setup.
* The agent still discovers tools through the standard MCP protocol — nothing changes for the agent's behavior.
* The model only ever sees the virtual MCP. The client receives the routing decision from it and executes the real MCP server.

**Status.** New in V2, alpha.

**Illustrative session share.** −10% (see table above). **Customer-traffic average (rolling 30 days), projected.** `tool_surface_reduction` reduces token costs by **\~25%** — a different baseline, not additive with the session figure.

## Output Brevity

Reduces verbosity in model responses without losing technical content. Same answer, fewer tokens. Single flag — no level parameter.

**Status.** New in V2.

For coding-agent sessions, output is a small share of total token volume (\~1%), so `output_brevity` is opt-in and disabled by default. For chat-style or RAG workloads where the model produces long-form answers, output is the dominant cost and `output_brevity` becomes the lever.

**Illustrative session share.** −30% (see table above). **Customer-traffic average (rolling 30 days).** Where enabled, `output_brevity` reduces total token costs by **6.5%** on average — a different baseline, not additive with the session figure.

**Academic note.** Recent work supports the broader claim — *Brevity Constraints Reverse Performance Hierarchies in Language Models* (Hakim, arXiv:2604.00025, March 2026) found that constraining models to brief responses can improve accuracy on certain benchmarks. The study is on open-weight models, not Claude/GPT directly.

## Reading the `compression` block

Every response that runs through any compression strategy carries a `compression` block on the response body. Use it to track savings per request.

```typescript theme={"dark"}
const response = await edgee.send({
  model: 'gpt-5.2',
  input: 'Long prompt with lots of context...',
});

if (response.compression) {
  console.log(response.compression.saved_tokens); // e.g. 450
  console.log(response.compression.cost_savings); // micro-units (1_000_000 = $1.00)
  console.log(response.compression.reduction);    // percentage, e.g. 48 → 48%
  console.log(response.compression.time_ms);      // ms spent on compression
}
```

Field reference:

| Field          | Type    | Meaning                                                               |
| -------------- | ------- | --------------------------------------------------------------------- |
| `saved_tokens` | integer | Input tokens removed (original count minus compressed count).         |
| `cost_savings` | integer | Estimated cost savings in micro-units. Divide by `1_000_000` for USD. |
| `reduction`    | number  | Percentage reduction in input tokens. `48` → 48%.                     |
| `time_ms`      | integer | Wall-clock time spent on compression.                                 |

The `usage.prompt_tokens` field on the same response reflects the **compressed** count actually billed by the provider, not the original input.

## Enabling and disabling

Three surfaces, in order of how most users will use them.

### CLI (default-on for coding agents)

When you launch a coding agent through the Edgee CLI, `tool_result_trimming` is enabled automatically — no console step required.

```bash theme={"dark"}
edgee launch claude
edgee launch codex
edgee launch opencode
```

`tool_surface_reduction` is opt-in. `output_brevity` is opt-in for coding-agent sessions because output is a small share of their volume.

### Console (per-key toggle)

In the [Edgee Console](https://www.edgee.ai), open **Dashboard** and manage your agent's settings right from the UI.

For team-managed keys, the same toggles are available per-member from **Team management → agent settings**. See [Team management](/features/team).

## Receipts

Customer-traffic averages, per technique, rolling 30 days — not aggregable across techniques (different baselines):

* `tool_result_trimming` — **−19%** on average
* `tool_surface_reduction` — **\~−25%** projected (alpha)
* `output_brevity` — **−6.5%** when enabled

Customer aggregate (rolling 30 days): approximately **20%** reduction in token bills across active customers, with zero measurable drift on SWE-Bench Verified samples.

## Next

<Card title="Observability" icon="chart-line" iconType="duotone" href="/features/observability">
  Track token usage, costs, and compression events per session and per team.
</Card>

<EdgeeSdk />
