Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/arjunkshah/supercompress/llms.txt

Use this file to discover all available pages before exploring further.

SuperCompress is a library — you wire it in wherever you build LLM prompts from long context. Whether you are calling OpenAI directly, running chains in LangChain, piping data through a shell script, or serving a browser demo, there is a pattern that fits without changing your surrounding application logic.

Integration overview

IntegrationWhen to use
Python importAny backend, scripts, notebooks
OpenAI-style wrapperChat APIs with messages[]
LangChain hookChains / agents with message history
Local HTTP serverDev tools, non-Python clients
Browser demoJudges, docs, no install

Integration patterns

The core compress_for_turn() function accepts a list of context blocks (strings) and a user query, then returns compressed text and a stats object. This is the lowest-level entry point and works in any Python environment — backend services, Jupyter notebooks, or batch scripts.
from supercompress import compress_for_turn

compressed, stats = compress_for_turn(
    context_blocks=[system_prompt, tool_output, chat_history],
    user_query=user_message,
    budget_ratio=0.35,
)
# Send `compressed` to your LLM instead of the full merged context
Track the sustainability impact of each compression call with the built-in metrics helper:
from supercompress.benchmarks.metrics import sustainability_from_tokens_saved

saved = stats.original_tokens - stats.kept_tokens
impact = sustainability_from_tokens_saved(saved)
print(impact.to_dict())

Policy selection quick reference

Use the policy argument to override the default SuperCompress learned policy with an explicit baseline, or omit it to let the library choose the best available option.
CallPolicy used
compress_context(text, q)SuperCompress (or H2O fallback if no checkpoint)
compress_context(..., policy=FIFO())Explicit FIFO baseline
compare_policies(text, q)All policies — returns dict keyed by policy name

Build docs developers (and LLMs) love