====== Setup Headroom (Context Compression Proxy) for 9Router ====== Documentation for installing and running **Headroom** (''headroom-ai'') as a local context compression proxy on port ''8787'' for **9Router** ===== 1. Install Python Virtual Environment Tools ===== Ensure ''python3-venv'' and ''python3-pip'' are installed (Python 3.10+ required): sudo apt update && sudo apt install -y python3-venv python3-pip **Verification:** python3 --version ---- ===== 2. Install headroom-ai with Compression Extras ===== Create a dedicated virtual environment and install ''headroom-ai'' with both ''proxy'' and ''ml'' extras (installing ''proxy'' alone will not perform meaningful compression): sudo python3 -m venv /opt/headroom sudo /opt/headroom/bin/pip install --upgrade pip sudo /opt/headroom/bin/pip install "headroom-ai[proxy,ml]" Create a symlink in ''/usr/local/bin'' so 9Router automatically detects the binary: sudo ln -sf /opt/headroom/bin/headroom /usr/local/bin/headroom **Verification:** which headroom && headroom --version Confirm the path resolves to ''/usr/local/bin/headroom''. ---- ===== 3. Create the systemd Service ===== Create a ''systemd'' unit file to run the Headroom proxy in the background on port ''8787'': sudo tee /etc/systemd/system/headroom.service > /dev/null < Reload ''systemd'', enable, and start the service: sudo systemctl daemon-reload sudo systemctl enable --now headroom **Verification:** sudo systemctl status headroom curl -s http://localhost:8787/health Ensure the service status is ''active (running)'' and ''/health'' returns a healthy response. ---- ===== 4. Enable Headroom in 9Router ===== - Restart 9Router so it detects the new ''headroom'' binary: sudo systemctl restart 9router - Open the 9Router dashboard (''http://:20128'') and go to **Endpoint -> Token Saver -> Headroom**. - Verify the status changed from **Not installed** to **Running** (''http://localhost:8787''). - Toggle **Compress context (Headroom)** to **ON**. ---- ===== Day-to-Day Management ===== ^ Task ^ Command ^ | View live compression logs | ''journalctl -u headroom -f'' | | Check service status | ''sudo systemctl status headroom'' | | Restart Headroom | ''sudo systemctl restart headroom'' | | Update Headroom | ''sudo /opt/headroom/bin/pip install -U "headroom-ai[proxy,ml]" && sudo systemctl restart headroom'' |