{"slug": "cut-your-llm-token-costs-for-free-with-contextpress", "title": "Cut Your LLM Token Costs for Free with ContextPress", "summary": "ContextPress, a Python library that compresses LLM context through rule-based logic rather than model calls, added five new compression stages since its initial release, according to a follow-up post by its developer. Benchmarks on 222 real conversation items across low, medium, and high presets — 666 runs total — showed the low preset cutting 6% of tokens while retaining 98.4% of hard facts, with the high preset delivering roughly eight times the savings at a real cost to retained facts. The library installs via pip and exposes a ContextManager class whose compress method takes a token_budget parameter, with three further stages — contractions, wordy-phrase compression, and number normalization — built but not yet enabled in any preset.", "body_md": "Your API bill grows every time your context gets longer. Input token cost is not usually the biggest number on your bill, but it is the most important part you can actually control. Noise, repeated instructions, and unnecessary detail in your context also push the model toward longer, more expensive answers, so the cost adds up on both ends.\n\nAnother gain here is optimizing the opportunity cost. As a developer, I work with a limited budget for coding agents. The more efficient I am with that budget, the harder I can push those agents, and the more I get done with them. Using ContextPress, I got more out of my coding agents on the same monthly budget, and it did not cost me anything extra to do it.\n\nA few things ContextPress does not need:\n\nContextPress cuts tokens by summarizing context, removing noise, and shortening long words and phrases, all through plain rule-based logic, not a model call. There are more advanced tools inside the package too, for when you need them. As a quick taste: utilization becomes usage, and application programming interface becomes API.\n\nJust do this:\n\n```\npip install contextpress\npython\nfrom contextpress import ContextManagercm = ContextManager(type=\"chat\")compressed = cm.compress(messages, token_budget=2000)\n```\n\nThat is the whole integration. Every token ContextPress removes is a token you stop paying for. I first wrote about ContextPress here: [Introducing ContextPress](https://pub.towardsai.net/introducing-contextpress-the-python-library-that-refactors-your-llm-context-c57965617edb). This is the follow-up: what got added since, and the numbers behind it.\n\nSince that first piece, ContextPress picked up five new stages. Lexical swaps expensive words for cheap synonyms, utilisation/utilization becomes use. Abbrev shortens roughly 300 common long forms, application programming interface becomes API. Alias catches a phrase repeated three or more times, spells it out once, then shortens every mention after. Structure minifies embedded JSON in tool payloads and RAG chunks. Trim, only on the high preset, drops the middle of a long thread and keeps the opening, the recent turns, and any tool call pairs intact.\n\nThree more stages, contractions, wordy-phrase compression, and number normalization, are built and ready, just not switched on in any preset yet.\n\nOne sentence shows most of it at once.\n\n**Sample Before:**\n\n*In order to utilize the API effectively, due to the fact that rate limits apply, we should implement caching for the application programming interface calls we make on a daily basis.*\n\n**Sample After, (low preset):**\n\n*To use the API effectively, because rate limits apply, we should implement caching for the API calls we make daily.*\n\nPracticically the same input, but with fewer tokens, you save money.\n\nFor the benchmarking, I used tokens saved and critical information loss as the main KPIs, both measured deterministically. LLM as a judge does not work well in this particular case, because whether a URL, a date, or an ID survived compression is a yes or no fact, not a judgment call. Asking a model to grade that just adds noise and cost, and cost is the one thing this whole library is trying to remove.\n\nSo the benchmark runs on 222 real conversation items, chats, agent tool threads, and RAG file contexts, across all three presets: low, medium, and high. That comes out to 666 runs total, a coincidence, not a reference to the number of the beast, and the whole thing finishes in about four minutes.\n\nThe check works like this: pull every hard fact out of the raw text first, URLs, versions, dates, IDs, then confirm each one survives compression at a token boundary. A stray “10” hiding inside “2010” does not count as a survivor.\n\nResults: low stays near-zero-risk: 6% improvements to the budget while 98.4% of every fact still there. high is the deep cut for a hard budget: about eight times the savings, at a real cost to retained facts. medium, roughly half of high's token savings for about the half its critical loss. choose based on your intent.\n\nFor a typical chat, median critical loss is 0% on both low and medium. The only preset where the median conversation loses anything is high, and that is trim doing exactly what it is supposed to do, dropping the middle of a long thread on purpose.\n\nPresets do not behave the same way on every kind of content, and it helps to know why before picking one for your own use case.\n\nis where the choice of preset matters most. Trim needs a long middle section to cut, and in a real conversation that middle section is usually where the facts live. That is why high's critical loss jumps once trim gets involved.\n\ndo not really have a middle to trim. That is why medium and high land close together on this kind of content. Recency, the stage that summarizes older turns, is doing almost all the work in both cases, and trim barely adds anything on top.\n\ntraces barely move across presets at all. Structure’s JSON cleanup is doing nearly the whole job by itself, since recency and trim rarely find anything to do on a short tool exchange.\n\nturns are already compact by nature. low and medium barely touch them, and only high's trim stage finds a little left to cut.\n\n```\npreset = cm.recommend_preset(messages, token_budget=500)result = cm.compress(messages, token_budget=500, compression=preset, return_stats=True)print(result.summary())# contextpress (chat, medium): 12 -> 8 turns, 842 -> 410 tokens (51.3% saved)\n```\n\npip install contextpress. Run it against your real tokens. These percentages are reproducible on your data too can bring your cost down.\n\nOpenAI, Anthropic, and Gemini discount requests that reuse an exact prefix they have already seen, that means all tokens the same order. That discount *needs a byte-identical match*. Recompress your whole history every turn, and stages like alias, repetition, and trim rewrite or drop earlier turns. The prefix changes, the next request becomes a cache miss, and on some providers you also eat a cache-write surcharge.\n\nCompress the wrong part of the conversation, and you can end up paying more than doing nothing.\n\nCheck it instead of assuming:\n\n``` python\nfrom contextpress.costs import compare_cache_tradeoff\nt = compare_cache_tradeoff(10_000, 9_400, cache_hit_rate=0.5, cache_read_multiplier=0.1)print(t.compress_is_cheaper, t.break_even_cache_hit_rate)\n```\n\nto fix the caching problem, compress only the new, uncached part of the conversation, keep a stable prefix (system prompt, tool schemas, an already-compacted history) untouched, and only recompact deliberately, not on every turn. I am adding a new release for handling the caching better very soon in the ContextPress library.\n\nPlease like, subscribe, visit the [GitHub](https://github.com/Taha-azizi/contextpress) page and feel free to contribute.\n\n[Cut Your LLM Token Costs for Free with ContextPress](https://pub.towardsai.net/cut-your-llm-token-costs-for-free-with-contextpress-3860fabaafe3) was originally published in [Towards AI](https://pub.towardsai.net) on Medium, where people are continuing the conversation by highlighting and responding to this story.", "url": "https://wpnews.pro/news/cut-your-llm-token-costs-for-free-with-contextpress", "canonical_source": "https://pub.towardsai.net/cut-your-llm-token-costs-for-free-with-contextpress-3860fabaafe3?source=rss----98111c9905da---4", "published_at": "2026-09-17 06:23:01+00:00", "updated_at": "2026-09-17 06:54:06.862165+00:00", "lang": "en", "topics": ["ai-tools", "developer-tools", "large-language-models", "ai-infrastructure"], "entities": ["ContextPress", "ContextManager", "Python", "Towards AI"], "alternates": {"html": "https://wpnews.pro/news/cut-your-llm-token-costs-for-free-with-contextpress", "markdown": "https://wpnews.pro/news/cut-your-llm-token-costs-for-free-with-contextpress.md", "text": "https://wpnews.pro/news/cut-your-llm-token-costs-for-free-with-contextpress.txt", "jsonld": "https://wpnews.pro/news/cut-your-llm-token-costs-for-free-with-contextpress.jsonld"}}