npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

n8n-nodes-headroom-token-optimizer

v1.1.6

Published

n8n community node plugin to optimize LLM token usage using Headroom context compression

Downloads

2,050

Readme

n8n-nodes-headroom-token-optimizer

This is an n8n community node plugin that optimizes LLM (Large Language Model) token usage in your workflows using Headroom context compression. It acts as an optimization layer between your n8n workflow and your LLM providers (e.g., OpenAI, Anthropic, or local Ollama).


Key Features

  • Direct Token Optimizer Node: A standard node that takes text or messages, compresses them using Headroom's pipeline (removing duplicate logs, redundant code, boilerplate, and long-range text), and outputs the compressed text alongside metrics:
    • tokensSaved: Number of tokens avoided.
    • originalTokens: Original token count.
    • compressedTokens: Optimized token count.
  • Model Middleware Node: A background wrapper that hooks into n8n's language model connections. It transparently intercepts all LLM calls (supporting invoke, stream, and batch requests) and compresses the prompts in the background before they reach the LLM.
  • Exposed Token Budget: Define a custom Token Budget parameter in both nodes. Compression will be dynamically triggered only when the prompt size exceeds this limit.
  • UI Savings Statistics: Automatically injects compression metrics (tokensSaved, originalTokens, compressedTokens) into the response_metadata of LLM output messages, making headroom savings visible directly in n8n execution history logs.

Prerequisites

To use this plugin, you must have a running Headroom proxy server instance.

Quick Start with Docker

Start the Headroom proxy pointing to your LLM endpoint (e.g. Ollama on the host):

docker run -d --name headroom-proxy \
  -p 8787:8787 \
  -e OPENAI_TARGET_API_URL=http://host.docker.internal:11434/v1 \
  ghcr.io/chopratejas/headroom:latest

Installation

In n8n Admin Panel

  1. Go to Settings > Community Nodes.
  2. Click Install a Node.
  3. Enter n8n-nodes-headroom-token-optimizer in the npm package name field.
  4. Agree to terms and click Install.

Usage Guide

1. Direct Token Optimizer Node

Use this node to compress large files, API responses, or logs before feeding them into your LLM prompt.

  • Mode: Choose between Text, Messages (JSON array of chat history), or Chat Input (to automatically hook into a Chat Trigger's input).
  • Token Budget: Set a target size (e.g. 2000). If the input contains more tokens than this budget, Headroom compresses it down.
  • Base URL: The address of your Headroom proxy (defaults to http://localhost:8787).
  • Model: The model name (used to calculate accurate tokenizer metrics, e.g., gpt-4o or granite4.1:3b).

2. Model Middleware Node

Use this node to wrap your language models transparently.

  1. Add a Headroom Model Middleware node.
  2. Connect it to the Model Middleware input of any n8n LLM Node (e.g. Ollama Chat Model or OpenAI Chat Model).
  3. Set your Token Budget (e.g., 1000) and Base URL.
  4. Now, any agent or chain using that model node will have its prompt automatically compressed in the background.

Local Development & Testing

Installation

Clone the repository and install dependencies:

npm install

Build Node Package

Compiles TypeScript files and copies icons:

npm run build

Run Integration Tests

We provide a local TypeScript integration test script that runs a complete cycle through the middleware, the local Headroom proxy, and a host Ollama instance:

npx ts-node test-headroom-ollama.ts

License

MIT