Mare Liberum

900 mTwilight zone

Guides · The engine room

/compress in a LiteLLM proxy or the Vercel AI SDK

Tool results are often the longest text an agent's model reads: a page as HTML, a JSON answer, a log. POST https://mareliberum.dev/compress gives such a text back smaller by lossless steps; a gateway between the agent and its model can send every long tool result there first. Both files below send only tool results of at least 2,000 characters, take the answer only when it is smaller in UTF-8 bytes, and keep the original text on any error or timeout.

What /compress does to a text

Only when you name a question (q) or a token budget (budget) does it leave parts out, and then it says so (lossy: true, x-sea-engine-lossy: 1). The gateways below name neither.

LiteLLM proxy

config.yaml: the lean door behind the proxy's MCP gateway (clients reach it at /mcp, or /mare_lean/mcp for this server alone)

mcp_servers:
  mare_lean:
    url: "https://mareliberum.dev/mcp/lean"
    transport: "http"
    auth_type: "none"

config.yaml: tool results through /compress before they reach the model (litellm_mare_compress.py beside config.yaml)

litellm_settings:
  callbacks: litellm_mare_compress.proxy_handler_instance

The callback: integrations/gateways/litellm_mare_compress.py, put beside config.yaml. It reads the tool results of OpenAI chat messages, Anthropic tool_result blocks and Responses API function_call_output items. Settings from the environment: MARE_COMPRESS_MIN_CHARS (2,000), MARE_COMPRESS_TIMEOUT (4 seconds per text), MARE_COMPRESS_MAX_TEXTS (8 texts per request), MARE_COMPRESS_URL. It remembers 256 answers in memory, so a conversation sent again sends no text twice and keeps the same prefix for prompt caching.

Checked against LiteLLM: MCP configuration reference · LiteLLM: call hooks (async_pre_call_hook)

Vercel AI SDK

Vercel AI SDK: every tool result through /compress (vercel-ai-mare-compress.ts)

import { wrapLanguageModel } from 'ai';
import { mareCompress } from './vercel-ai-mare-compress';

const model = wrapLanguageModel({ model: yourModel, middleware: mareCompress() });

The middleware: integrations/gateways/vercel-ai-mare-compress.ts, no packages (fetch and Web Crypto). Options: minChars (2,000), timeoutMs (4,000), maxTexts (8), url, fetch. It remembers 256 answers as the callback does.

Checked against AI SDK: language model middleware · LiteLLM: call hooks

Your own pipeline

curl: a page you hold, as Markdown (Accept: text/plain gives only the text)

curl -s https://mareliberum.dev/compress -H 'content-type: text/html' --data-binary @page.html

Python, no packages

import json, urllib.request

def squeeze(text: str) -> str:
    req = urllib.request.Request("https://mareliberum.dev/compress", data=json.dumps({"text": text}).encode(), headers={"content-type": "application/json"})
    try:
        with urllib.request.urlopen(req, timeout=5) as r:
            out = json.load(r).get("out")
        return out if isinstance(out, str) and len(out.encode()) < len(text.encode()) else text
    except Exception:
        return text

TypeScript, no packages

export async function squeeze(text: string): Promise<string> {
  try {
    const r = await fetch('https://mareliberum.dev/compress', { method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify({ text }), signal: AbortSignal.timeout(5000) });
    const out = (await r.json())?.out;
    return r.ok && typeof out === 'string' && new TextEncoder().encode(out).length < new TextEncoder().encode(text).length ? out : text;
  } catch {
    return text;
  }
}

Limits and answers

What leaves your proxy, and what is kept

Only the text of the tool results sent. What an agent posts to /compress is never stored, logged or counted beyond its size in bytes. The only versions kept, for since=, are pages read through /r/ (public pages the reader reads anyway): in memory, bounded in bytes and to 24 hours, never anything posted. Leave the callback out for tool results you may not send to a third party.

Where it spares nothing

A tool result that is short, plain text without repeats, or compact JSON that holds no table comes back no smaller, and the gateway keeps it. And /compress is not for a model to call itself with text it already holds. As GET /compress says it: A model that pastes text it already holds into a tool call pays for it as output tokens (about five times the price of input) and loses; to read a page short, use /r/<address>?budget=<tokens>.

What it costs

Up to 10,000 tokens saved by the lossless levers stay free per network and UTC day; above that an answer costs 20 % of the tokens it saved, at USD 2 per million, settled over x402 in one payment from $0.05; without payment the lean answers pause and the normal answers continue, and unpaid tolls are not collected. Tested: the snippets run against a node in tools/pipes-proof.mjs; the callback and the middleware have their own tests beside them.

More guides

Sources of every number on this page: /engine (the bench run) · /proof (the run) · the toll · the code: github.com/daoudandiaye98-alt/mare-liberum