Compress tool outputs, logs, files, and RAG chunks before they reach the LLM. 20% fewer tokens for coding agents, 60-95% fewer tokens for JSON, same answers. Library, proxy, MCP server.
Python agentaianthropicclaude-codecompressioncontext-engineeringcontext-windowcursorfastapilangchainllmmcpopenaiprompt-engineeringproxypythonragtoken-optimizationtokenstypescript
Rename tool output compression parallelism env
jamesx0416cfcaf0e364e8
diff --git a/headroom/proxy/handlers/openai.py b/headroom/proxy/handlers/openai.pyindex dcfe6f8a1..9835ad6a1 100644--- a/headroom/proxy/handlers/openai.py+++ b/headroom/proxy/handlers/openai.py@@ -52,7 +52,7 @@ logger = logging.getLogger("headroom.proxy")_OPENAI_RESPONSES_UNIT_CACHE_MAX_ENTRIES = 10_000_OPENAI_RESPONSES_UNIT_CACHE_VERSION = "openai_responses_unit_v1"-_OPENAI_RESPONSES_UNIT_PARALLELISM_ENV = "HEADROOM_OPENAI_RESPONSES_UNIT_PARALLELISM"+_OPENAI_RESPONSES_UNIT_PARALLELISM_ENV = "HEADROOM_TOOL_OUTPUT_COMPRESSION_PARALLELISM"_OPENAI_RESPONSES_UNIT_PARALLELISM_DEFAULT = 4_OPENAI_RESPONSES_UNIT_PARALLELISM_MAX = 16_OPENAI_RESPONSES_UNIT_CACHE_INIT_LOCK = threading.RLock()diff --git a/tests/test_openai_responses_compression_units.py b/tests/test_openai_responses_compression_units.pyindex c0b8329ac..aaa8b5212 100644--- a/tests/test_openai_responses_compression_units.py+++ b/tests/test_openai_responses_compression_units.py@@ -28,16 +28,16 @@ def _handler_with_router(router: ContentRouter) -> OpenAIHandlerMixin:def test_openai_responses_unit_parallelism_env_defaults_and_clamps(monkeypatch):- monkeypatch.delenv("HEADROOM_OPENAI_RESPONSES_UNIT_PARALLELISM", raising=False)+ monkeypatch.delenv("HEADROOM_TOOL_OUTPUT_COMPRESSION_PARALLELISM", raising=False)assert openai_handler._openai_responses_unit_parallelism() == 4- monkeypatch.setenv("HEADROOM_OPENAI_RESPONSES_UNIT_PARALLELISM", "bad")+ monkeypatch.setenv("HEADROOM_TOOL_OUTPUT_COMPRESSION_PARALLELISM", "bad")assert openai_handler._openai_responses_unit_parallelism() == 4- monkeypatch.setenv("HEADROOM_OPENAI_RESPONSES_UNIT_PARALLELISM", "0")+ monkeypatch.setenv("HEADROOM_TOOL_OUTPUT_COMPRESSION_PARALLELISM", "0")assert openai_handler._openai_responses_unit_parallelism() == 1- monkeypatch.setenv("HEADROOM_OPENAI_RESPONSES_UNIT_PARALLELISM", "999")+ monkeypatch.setenv("HEADROOM_TOOL_OUTPUT_COMPRESSION_PARALLELISM", "999")assert openai_handler._openai_responses_unit_parallelism() == 16@@ -271,7 +271,7 @@ def test_openai_responses_adapter_reuses_identical_tool_output_in_same_request()def test_openai_responses_adapter_parallelizes_cache_misses_preserving_order(monkeypatch):- monkeypatch.setenv("HEADROOM_OPENAI_RESPONSES_UNIT_PARALLELISM", "4")+ monkeypatch.setenv("HEADROOM_TOOL_OUTPUT_COMPRESSION_PARALLELISM", "4")router = ContentRouter()lock = threading.Lock()release = threading.Event()diff --git a/tests/test_openai_responses_t3_replay_regression.py b/tests/test_openai_responses_t3_replay_regression.pyindex 494062536..a4374ee54 100644--- a/tests/test_openai_responses_t3_replay_regression.py+++ b/tests/test_openai_responses_t3_replay_regression.py@@ -96,7 +96,7 @@ def _json_bytes(value: object) -> int:def test_t3_failed_size_responses_payload_parallelizes_uncached_tool_outputs(monkeypatch):- monkeypatch.setenv("HEADROOM_OPENAI_RESPONSES_UNIT_PARALLELISM", "4")+ monkeypatch.setenv("HEADROOM_TOOL_OUTPUT_COMPRESSION_PARALLELISM", "4")case = T3_FAILED_CASES[0]router = ContentRouter()lock = threading.Lock()