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
style: format files for CI
Adryan Eka Vandra7e53362e62f8
diff --git a/headroom/proxy/handlers/anthropic.py b/headroom/proxy/handlers/anthropic.pyindex 649d7b638..a9625672c 100644--- a/headroom/proxy/handlers/anthropic.py+++ b/headroom/proxy/handlers/anthropic.py@@ -411,8 +411,7 @@ class AnthropicHandlerMixin:"error": {"type": "service_unavailable","message": (- "Anthropic pre-upstream queue is saturated. "- "Please retry shortly."+ "Anthropic pre-upstream queue is saturated. Please retry shortly."),},},diff --git a/headroom/proxy/server.py b/headroom/proxy/server.pyindex 64dd6d71a..cfdc225bb 100644--- a/headroom/proxy/server.py+++ b/headroom/proxy/server.py@@ -692,8 +692,7 @@ class HeadroomProxy(_origin,)logger.info(- "Anthropic pre-upstream timeouts: acquire=%.1fs compression=%.1fs "- "memory_context=%.1fs",+ "Anthropic pre-upstream timeouts: acquire=%.1fs compression=%.1fs memory_context=%.1fs",self.anthropic_pre_upstream_acquire_timeout_seconds,float(COMPRESSION_TIMEOUT_SECONDS),self.anthropic_pre_upstream_memory_context_timeout_seconds,diff --git a/tests/test_proxy_codex_route_aliases.py b/tests/test_proxy_codex_route_aliases.pyindex d74529d2e..780619995 100644--- a/tests/test_proxy_codex_route_aliases.py+++ b/tests/test_proxy_codex_route_aliases.py@@ -118,9 +118,7 @@ def test_codex_responses_subpath_aliases_delegate_to_passthrough():),],)-def test_codex_responses_subpath_passthrough_derives_chatgpt_routing_from_jwt(- path, expected_url-):+def test_codex_responses_subpath_passthrough_derives_chatgpt_routing_from_jwt(path, expected_url):class FakeAsyncClient:def __init__(self) -> None:self.calls: list[tuple[str, str, dict[str, str]]] = []diff --git a/tests/test_proxy_google_cloudcode_route_aliases.py b/tests/test_proxy_google_cloudcode_route_aliases.pyindex 5f2a85592..b94e918fd 100644--- a/tests/test_proxy_google_cloudcode_route_aliases.py+++ b/tests/test_proxy_google_cloudcode_route_aliases.py@@ -98,9 +98,7 @@ def test_cloudcode_route_uses_cloudcode_api_override(monkeypatch):monkeypatch.setattr(HeadroomProxy, "_stream_response", fake_stream)with TestClient(- create_app(- ProxyConfig(optimize=False, cloudcode_api_url="https://cloudcode-proxy.test/v1")- )+ create_app(ProxyConfig(optimize=False, cloudcode_api_url="https://cloudcode-proxy.test/v1"))) as client:response = client.post("/v1/v1internal:streamGenerateContent",@@ -150,9 +148,7 @@ def test_antigravity_route_does_not_cross_route_to_cloudcode_override(monkeypatcmonkeypatch.setattr(HeadroomProxy, "_stream_response", fake_stream)with TestClient(- create_app(- ProxyConfig(optimize=False, cloudcode_api_url="https://cloudcode-proxy.test")- )+ create_app(ProxyConfig(optimize=False, cloudcode_api_url="https://cloudcode-proxy.test"))) as client:response = client.post("/v1internal:streamGenerateContent",@@ -175,9 +171,7 @@ def test_cloudcode_override_does_not_leak_between_app_instances(monkeypatch):monkeypatch.setattr(HeadroomProxy, "_stream_response", fake_stream)with TestClient(- create_app(- ProxyConfig(optimize=False, cloudcode_api_url="https://cloudcode-proxy.test")- )+ create_app(ProxyConfig(optimize=False, cloudcode_api_url="https://cloudcode-proxy.test"))) as client:first = client.post("/v1internal:streamGenerateContent",@@ -193,6 +187,12 @@ def test_cloudcode_override_does_not_leak_between_app_instances(monkeypatch):)assert first.status_code == 200- assert first.json()["url"] == "https://cloudcode-proxy.test/v1internal:streamGenerateContent?alt=sse"+ assert (+ first.json()["url"]+ == "https://cloudcode-proxy.test/v1internal:streamGenerateContent?alt=sse"+ )assert second.status_code == 200- assert second.json()["url"] == "https://cloudcode-pa.googleapis.com/v1internal:streamGenerateContent?alt=sse"+ assert (+ second.json()["url"]+ == "https://cloudcode-pa.googleapis.com/v1internal:streamGenerateContent?alt=sse"+ )diff --git a/tests/test_proxy_streaming_ratelimit_headers.py b/tests/test_proxy_streaming_ratelimit_headers.pyindex d11d41c5c..c6a69857c 100644--- a/tests/test_proxy_streaming_ratelimit_headers.py+++ b/tests/test_proxy_streaming_ratelimit_headers.py@@ -220,9 +220,7 @@ class TestStreamingRatelimitHeaderForwarding:"content-length": "42",})- mock_response.aread = AsyncMock(- return_value=b'{"error":{"message":"capacity exhausted"}}'- )+ mock_response.aread = AsyncMock(return_value=b'{"error":{"message":"capacity exhausted"}}')mock_response.aclose = AsyncMock()mock_request = MagicMock()