Quickstart
Get Headroom running in 5 minutes. Install, compress, and send to your LLM with fewer tokens.
This guide gets you from zero to compressed LLM calls in under 5 minutes.
1. Install
# Python project or virtualenv: enough for compress(), no API key, no model download
pip install headroom-ai
# CLI, proxy and `headroom wrap` on your machine
uv tool install --python 3.13 "headroom-ai[all]"[all] adds the proxy, the MCP server, the Kompress model and more; compress()
needs only the base package.
TypeScript SDK requires the proxy
The TypeScript SDK sends messages to a local Headroom proxy for compression. Start the proxy before using the TS SDK:
uv tool install --python 3.13 "headroom-ai[proxy]"
# or, inside a Python project: pip install "headroom-ai[proxy]"
headroom proxy --port 8787The proxy runs the compression pipeline (Python) and exposes an HTTP API that the TS SDK calls.
2. Compress messages
from headroom import compress
import json
messages = [
{"role": "system", "content": "You analyze search results."},
{"role": "user", "content": "Search for Python tutorials."},
{
"role": "assistant",
"content": None,
"tool_calls": [{
"id": "call_1",
"type": "function",
"function": {"name": "search", "arguments": '{"q": "python"}'},
}],
},
{
"role": "tool",
"tool_call_id": "call_1",
"content": json.dumps({
"results": [
{"title": f"Result {i}", "snippet": f"Description {i}", "score": 100 - i}
for i in range(500)
]
}),
},
{"role": "user", "content": "What are the top 3 results?"},
]
result = compress(messages, model="gpt-4o")No provider key needed to try it
The Python call runs in-process. HEADROOM_OFFLINE=1 makes it zero-network as
well (no update check, no model or pricing-table downloads):
HEADROOM_OFFLINE=1 python -c "from headroom import compress; log='\n'.join(f'INFO step {i} ok' for i in range(3000))+'\nFATAL disk full'; r=compress([{'role':'user','content':'What failed?'},{'role':'assistant','content':None,'tool_calls':[{'id':'c1','type':'function','function':{'name':'logs','arguments':'{}'}}]},{'role':'tool','tool_call_id':'c1','content':log}], model='gpt-4o'); print(r.tokens_before, '->', r.tokens_after, 'FATAL kept:', 'FATAL' in str(r.messages))"A FastAPI endpoint built on the same call is one page away.
3. Send to your LLM
Use the compressed messages exactly like the originals:
from openai import OpenAI
client = OpenAI()
response = client.chat.completions.create(
model="gpt-4o",
messages=result.messages,
)
print(response.choices[0].message.content)4. Check your savings
print(f"Tokens before: {result.tokens_before}")
print(f"Tokens after: {result.tokens_after}")
print(f"Tokens saved: {result.tokens_saved}")
print(f"Compression: {result.compression_ratio:.0%}")
print(f"Transforms: {result.transforms_applied}")Example output:
Tokens before: 45000
Tokens after: 4500
Tokens saved: 40500
Compression: 90%
Transforms: ['smart_crusher', 'cache_aligner']Alternative: proxy mode (zero code changes)
Using Claude Code inside VS Code?
Run headroom wrap vscode-claude, reload the VS Code window once, and keep the
wrapper running while you use the official Claude Code extension. See the
complete VS Code Claude Code guide for verification,
undo steps, custom profiles, and remote development.
If you do not want to change any code, run Headroom as a proxy and point your existing client at it:
# Start the proxy
headroom proxy --port 8787
# Point Claude Code at it
ANTHROPIC_BASE_URL=http://localhost:8787 claude
# Or any OpenAI-compatible client
OPENAI_BASE_URL=http://localhost:8787/v1 your-appAll requests flow through Headroom automatically. Check savings at any time:
curl http://localhost:8787/stats
# {"requests_total": 42, "tokens_saved_total": 125000, ...}What gets compressed
The biggest savings come from tool outputs -- search results, database rows, log files, API responses. Headroom auto-detects the content type and routes it to the best compressor. No configuration needed.
| Content type | Compressor | Typical savings |
|---|---|---|
| JSON arrays | SmartCrusher | varies with array size and redundancy |
| Source code | CodeCompressor | opt-in; disabled by default |
| Build/test logs | LogCompressor | varies with log verbosity |
| Search results | SearchCompressor | varies with result set size |
| Plain text | Kompress | varies with redundancy |
Savings depend heavily on how repetitive the content is -- see Benchmarks for measured numbers on real workloads.
Next steps
Introduction
Headroom (headroom-ai) compresses tool outputs, logs, JSON, RAG results and chat history before each LLM call, to reduce input tokens and token cost and fit a context window. Python library (no API key), proxy and MCP server. Same answers, fewer tokens.
Installation
Install Headroom via pip, npm, or Docker. Includes all Python extras, TypeScript setup, Docker image tags, and environment variables.