Headroom

Installation

Install Headroom via pip, npm, or Docker. Includes all Python extras, TypeScript setup, Docker image tags, and environment variables.

Python

Headroom requires Python 3.10+ and is published as headroom-ai on PyPI.

Core package

pip install headroom-ai

The core package includes the compress() function, SmartCrusher, CacheAligner, and IntelligentContext. No heavy dependencies.

Extras

Install only what you need, or grab everything with [all]:

pip install "headroom-ai[all]"
ExtraWhat it addsInstall command
proxyProxy server, MCP tools, HTTP APIpip install "headroom-ai[proxy]"
mlKompress (ModernBERT text compression, requires PyTorch)pip install "headroom-ai[ml]"
codeCodeCompressor (tree-sitter AST parsing)pip install "headroom-ai[code]"
mcpMCP server tools (headroom_compress, headroom_retrieve, headroom_stats)pip install "headroom-ai[mcp]"
langchainLangChain HeadroomChatModel wrapperpip install "headroom-ai[langchain]"
agnoAgno HeadroomAgnoModel wrapperpip install "headroom-ai[agno]"
evalsEvaluation framework (GSM8K, SQuAD, BFCL benchmarks)pip install "headroom-ai[evals]"
allEverything abovepip install "headroom-ai[all]"

You can combine extras:

pip install "headroom-ai[proxy,langchain,ml]"

Verify the install

python -c "import headroom; print(headroom.__version__)"

TypeScript / Node.js

The TypeScript SDK is published as headroom-ai on npm. It requires Node.js 18+.

npm install headroom-ai

Or with other package managers:

pnpm add headroom-ai
yarn add headroom-ai

The TS SDK needs a running proxy

The TypeScript SDK sends messages to the Headroom proxy over HTTP for compression. The proxy runs the full compression pipeline (Python). Start it before using the SDK:

pip install "headroom-ai[proxy]"
headroom proxy --port 8787

Then point the SDK at it:

import { compress } from 'headroom-ai';

const result = await compress(messages, {
  baseUrl: 'http://localhost:8787',
});

Verify the install

node -e "const h = require('headroom-ai'); console.log('headroom-ai loaded')"

Docker

Pre-built images are published to GitHub Container Registry on every release.

docker pull ghcr.io/chopratejas/headroom:latest
docker run -p 8787:8787 ghcr.io/chopratejas/headroom:latest

Image tags

TagExtrasBase imageDescription
latestproxyDebian slimDefault image, runs the proxy
<version>proxyDebian slimPinned version
nonrootproxyDebian slimRuns as non-root user
codeproxy,codeDebian slimIncludes tree-sitter for code compression
code-nonrootproxy,codeDebian slimCode compression, non-root
slimproxyDistrolessMinimal image, no shell
slim-nonrootproxyDistrolessMinimal, non-root
code-slimproxy,codeDistrolessCode compression, minimal
code-slim-nonrootproxy,codeDistrolessCode compression, minimal, non-root

Build from source

Use Docker Bake for multi-variant builds:

# List all targets
docker buildx bake --list targets

# Build the default runtime image
docker buildx bake runtime-default

# Build a specific variant with custom registry
docker buildx bake runtime-code-slim-nonroot \
  --set '*.tags=my-registry/headroom:code-slim-nonroot'

Environment variables

These variables configure Headroom at runtime. Set them in your shell, .env file, or container environment.

LLM provider keys

VariableDescription
OPENAI_API_KEYOpenAI API key (used when proxying to OpenAI)
ANTHROPIC_API_KEYAnthropic API key (used when proxying to Anthropic)
AWS_ACCESS_KEY_ID / AWS_SECRET_ACCESS_KEYAWS credentials for Bedrock backend
GOOGLE_APPLICATION_CREDENTIALSGoogle Cloud credentials for Vertex AI backend

Proxy configuration

VariableDefaultDescription
HEADROOM_PORT8787Port the proxy listens on
HEADROOM_HOST0.0.0.0Host the proxy binds to
HEADROOM_MODEoptimizeDefault mode: optimize, audit, or passthrough
HEADROOM_LOG_LEVELINFOLogging level

TypeScript SDK

VariableDefaultDescription
HEADROOM_BASE_URLhttp://localhost:8787Proxy URL for the TypeScript SDK
HEADROOM_API_KEY(none)API key if the proxy requires auth

Next steps

On this page