Headroom Model Middleware
AI-generatedSummary
Wraps a connected chat model with Headroom middleware that compresses prompts before supported model calls. The tokenizer selection controls token counting only; it does not change the connected model.
Inputs
- Connected Model (required) — Connect an n8n chat model to the required Model input.
- Tokenizer Model (required) — Choose the model family Headroom should use to count tokens; defaults to GPT-4o. Select Custom to provide a LiteLLM-compatible model identifier in Custom Tokenizer Model.
- Token Budget — Defaults to 0, which omits the budget option and means Headroom's compression is not limited by a configured token budget. A positive value is passed to Headroom as the token budget.
- Base URL (required) — Headroom proxy or API URL; defaults to http://localhost:8787.
- API Key — Optional key for Headroom Cloud.
- Fallback on Error — Defaults to true. If compression fails, the original model call proceeds with its uncompressed arguments; when false, the node raises an operation error.
- Compress User Messages — Defaults to true; configures whether Headroom compresses user messages.
- Compress System Messages — Defaults to false; configures whether Headroom compresses system messages.
- Timeout (Ms) — Headroom request timeout in milliseconds; defaults to 30000.
- Retries — Retry count for transient failures; defaults to 1.
Output shape
A connected ai_languageModel output wrapping the same model instance.
Intercepts supported methods including generate, invoke, call, batch, _generate, _streamResponseChunks, and _stream. It compresses string inputs, message objects, message arrays, and batches before forwarding them. Compression token statistics may be attached to response metadata when the returned response has a supported metadata shape.