Who it is forA Python developer building an LLM feature who wants lower per-request cost without rewriting the app.
The problemTool results, logs and retrieved chunks are sent to the model in full, even when most of the text is repetition.
The outcomeYour app passes compressed messages to the provider and prints how many tokens were saved.
What you need first
- Python 3.13 with uv, or pip, to install the headroom-ai package
- An account with an LLM provider such as Anthropic or OpenAI
- A coding agent or app that sends prompts through an API
Steps
- Install the package with
pip install "headroom-ai[all]" - Import the library with
from headroom import compress - Pass your message list to
compress(messages, model="gpt-4o")and sendresult.messagesto the provider - Print
result.tokens_savedandresult.compression_ratioto check the effect
Prompt for your agent
Using the repo headroomlabs-ai/headroom, add a compress() call to the LLM request in <file-path>, passing the message list through headroom's compress function before the provider call. Expected output: the same answer with a printed token saving. Verify that the request still succeeds and that tokens_saved is greater than zero for a payload with repeated JSON.
Caveat. The README gives a benchmark table for one seeded scenario set, so measure your own payloads with Headroom savings or the printed result values before you rely on a percentage.
Use this in your AI agent
Ask your agent
Using the Deduped MCP, get the setup steps for headroomlabs-ai/headroom and "Shrink messages in a Python app before each LLM call"
Add Deduped to Claude Code once
claude mcp add --transport http deduped https://dedupedai.com/mcp
Every Monday: the 5 hottest repos and exactly how to use them. Free, one email a week, unsubscribe anytime.
Get them freeShare: X LinkedIn Hacker News Email Copy link
Third-party repos we don't own. AI-written use cases can be wrong. Disclaimer