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
Fix image token counting: Anthropic images counted as text tokens
chopratejasdf664d5ad95f
diff --git a/headroom/tokenizers/base.py b/headroom/tokenizers/base.pyindex 6e0a5745f..3b449c0ac 100644--- a/headroom/tokenizers/base.py+++ b/headroom/tokenizers/base.py@@ -132,8 +132,11 @@ class BaseTokenizer(ABC):if part_type == "text":total += self.count_text(part.get("text", ""))- elif part_type == "image_url":- # Images have fixed token cost (varies by model)+ elif part_type in ("image_url", "image"):+ # Images have fixed token cost — NOT tokenized as text.+ # Anthropic images are type="image" with base64 in source.data.+ # Without this, the base64 string gets json.dumps'd and counted+ # as text tokens (1MB image = ~330K fake tokens).total += 85 # Base image token countelif part_type == "tool_result":content = part.get("content", "")