DEDUPED Hot AI repos. Real use cases. What people build. Get the Monday 5

How to shrink messages in a Python app before each LLM call with Headroom

Add a compress() call to existing Python code so the model receives fewer tokens.

Short answer: Install the package with pip install "headroom-ai[all]"; then import the library with from headroom import compress; Pass your message list to compress(messages, model="gpt-4o") and send result.messages to the provider. All steps.

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

  1. Install the package with pip install "headroom-ai[all]"
  2. Import the library with from headroom import compress
  3. Pass your message list to compress(messages, model="gpt-4o") and send result.messages to the provider
  4. Print result.tokens_saved and result.compression_ratio to 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

Cursor, ChatGPT, others

Share: X LinkedIn Hacker News Email Copy link

Third-party repos we don't own. AI-written use cases can be wrong. Disclaimer