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(startup): suppress proxy startup log noise (#619)
Patrick A45559011b16a
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex dd66300bb..1905419f3 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -6,6 +6,13 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).+## [Unreleased]++### Bug Fixes++* **startup:** suppress proxy startup log noise — litellm banner, trafilatura parse errors, HuggingFace Hub unauthenticated warnings, tiktoken fallback warning, and httpx INFO lines from sentence_transformers HEAD checks. Affected files: `headroom/providers/litellm.py`, `headroom/transforms/html_extractor.py`, `headroom/memory/adapters/embedders.py`, `headroom/providers/anthropic.py`, `headroom/providers/registry.py`, `headroom/image/onnx_router.py`, `headroom/transforms/kompress_compressor.py`.++## [0.23.0](https://github.com/chopratejas/headroom/compare/v0.22.4...v0.23.0) (2026-06-04)### Featuresdiff --git a/headroom/image/onnx_router.py b/headroom/image/onnx_router.pyindex 02af92efa..64ceeefa6 100644--- a/headroom/image/onnx_router.py+++ b/headroom/image/onnx_router.py@@ -20,7 +20,7 @@ from typing import Anyimport numpy as npfrom headroom.image.trained_router import ImageSignals, RouteDecision, Technique-from headroom.onnx_runtime import create_cpu_session_options+from headroom.onnx_runtime import create_cpu_session_options, hf_hub_download_local_firstlogger = logging.getLogger(__name__)@@ -57,19 +57,18 @@ class OnnxTechniqueRouter:returnimport onnxruntime as ort- from huggingface_hub import hf_hub_downloadfrom tokenizers import Tokenizerlogger.info("Loading technique-router ONNX INT8...")- model_path = hf_hub_download(_TECHNIQUE_ROUTER_REPO, "model_quantized.onnx")+ model_path = hf_hub_download_local_first(_TECHNIQUE_ROUTER_REPO, "model_quantized.onnx")self._classifier_session = ort.InferenceSession(model_path,create_cpu_session_options(ort),providers=["CPUExecutionProvider"],)- tokenizer_path = hf_hub_download(_TECHNIQUE_ROUTER_REPO, "tokenizer.json")+ tokenizer_path = hf_hub_download_local_first(_TECHNIQUE_ROUTER_REPO, "tokenizer.json")self._tokenizer = Tokenizer.from_file(tokenizer_path)self._tokenizer.enable_truncation(max_length=64)self._tokenizer.enable_padding(length=64)@@ -77,7 +76,7 @@ class OnnxTechniqueRouter:# Load label mappingimport json- config_path = hf_hub_download(_TECHNIQUE_ROUTER_REPO, "config.json")+ config_path = hf_hub_download_local_first(_TECHNIQUE_ROUTER_REPO, "config.json")with open(config_path) as f:config = json.load(f)self._id2label = {int(k): v for k, v in config.get("id2label", {}).items()}@@ -93,18 +92,17 @@ class OnnxTechniqueRouter:returnimport onnxruntime as ort- from huggingface_hub import hf_hub_downloadlogger.info("Loading SigLIP ONNX INT8 image encoder...")- model_path = hf_hub_download(_SIGLIP_ENCODER_REPO, "image_encoder_int8.onnx")+ model_path = hf_hub_download_local_first(_SIGLIP_ENCODER_REPO, "image_encoder_int8.onnx")self._siglip_session = ort.InferenceSession(model_path,create_cpu_session_options(ort),providers=["CPUExecutionProvider"],)- embeddings_path = hf_hub_download(_SIGLIP_ENCODER_REPO, "text_embeddings.npz")+ embeddings_path = hf_hub_download_local_first(_SIGLIP_ENCODER_REPO, "text_embeddings.npz")loaded = np.load(embeddings_path)self._text_embeddings = {k: loaded[k] for k in loaded.files}diff --git a/headroom/memory/adapters/embedders.py b/headroom/memory/adapters/embedders.pyindex 1df384028..73334cd57 100644--- a/headroom/memory/adapters/embedders.py+++ b/headroom/memory/adapters/embedders.py@@ -13,17 +13,30 @@ from __future__ import annotationsimport asyncioimport loggingimport os+import warningsfrom functools import cached_propertyfrom typing import TYPE_CHECKING, Any, castimport numpy as npfrom headroom.models.config import ML_MODEL_DEFAULTS-from headroom.onnx_runtime import create_cpu_session_options+from headroom.onnx_runtime import create_cpu_session_options, hf_hub_download_local_firstif TYPE_CHECKING:from sentence_transformers import SentenceTransformer+# Suppress HuggingFace Hub warnings about missing tokens and rate limits.+# These appear whenever hf_hub_download is called without HF_TOKEN set.+# We operate in an authenticated-optional mode; warnings are not actionable.+os.environ.setdefault("HF_HUB_DISABLE_PROGRESS_BARS", "1")+os.environ.setdefault("HF_HUB_DISABLE_IMPLICIT_TOKEN", "1")+warnings.filterwarnings("ignore", category=UserWarning, module="huggingface_hub")+# Also silence the huggingface_hub logger which emits rate-limit advisory messages.+logging.getLogger("huggingface_hub").setLevel(logging.ERROR)+# sentence_transformers uses httpx to check model file manifests on every startup.+# These HEAD/GET requests generate INFO lines per worker; suppress to WARNING.+logging.getLogger("httpx").setLevel(logging.WARNING)+logger = logging.getLogger(__name__)@@ -305,13 +318,13 @@ class OnnxLocalEmbedder:returnimport onnxruntime as ort- from huggingface_hub import hf_hub_downloadfrom tokenizers import Tokenizerlogger.info("Loading ONNX embedding model (all-MiniLM-L6-v2, ~86MB)...")- model_path = hf_hub_download(self.ONNX_REPO, "model.onnx")- tok_path = hf_hub_download(self.ONNX_REPO, "tokenizer.json")+ # Prefer local cache to avoid a redundant network HEAD on warm starts.+ model_path = hf_hub_download_local_first(self.ONNX_REPO, "model.onnx")+ tok_path = hf_hub_download_local_first(self.ONNX_REPO, "tokenizer.json")# Keep a small thread pool for Docker compatibility and disable ORT's# CPU memory arena/pattern caches so long-running proxy workers do notdiff --git a/headroom/onnx_runtime.py b/headroom/onnx_runtime.pyindex 38f3329a5..214f7efcd 100644--- a/headroom/onnx_runtime.py+++ b/headroom/onnx_runtime.py@@ -7,6 +7,32 @@ import sysfrom typing import Any+def hf_hub_download_local_first(repo_id: str, filename: str) -> str:+ """Download a file from HuggingFace Hub, preferring the local cache.++ Tries ``local_files_only=True`` first to avoid a network HEAD request when+ the model is already cached. Falls back to a normal (network-allowed)+ download on the first cold start.++ Args:+ repo_id: HuggingFace Hub repository identifier (e.g. ``"org/model"``).+ filename: Filename within the repository.++ Returns:+ Absolute path to the local cached file.++ Raises:+ Any exception raised by ``hf_hub_download`` on a genuine download failure.+ """+ from huggingface_hub import hf_hub_download+ from huggingface_hub.errors import EntryNotFoundError, LocalEntryNotFoundError++ try:+ return str(hf_hub_download(repo_id, filename, local_files_only=True))+ except (LocalEntryNotFoundError, EntryNotFoundError, OSError):+ return str(hf_hub_download(repo_id, filename))++def create_cpu_session_options(ort: Any,*,diff --git a/headroom/providers/anthropic.py b/headroom/providers/anthropic.pyindex 9d0f20387..88572febf 100644--- a/headroom/providers/anthropic.py+++ b/headroom/providers/anthropic.py@@ -36,6 +36,9 @@ def _get_litellm_clients() -> tuple[Any | None, Any | None]:try:import litellm++ litellm.suppress_debug_info = True+ litellm.set_verbose = Falsefrom litellm import get_model_info as litellm_get_model_infoexcept ImportError:return None, None@@ -223,13 +226,15 @@ class AnthropicTokenCounter(TokenCounter):Falls back to tiktoken approximation only when no client is available."""- def __init__(self, model: str, client: Any = None):+ def __init__(self, model: str, client: Any = None, warn: bool = True):"""Initialize token counter.Args:model: Anthropic model name.client: Optional anthropic.Anthropic client for API-based counting.If not provided, falls back to tiktoken approximation.+ warn: If False, suppresses the no-client UserWarning (useful for+ internal proxy usage where approximation is intentional)."""global _FALLBACK_WARNING_SHOWN@@ -238,7 +243,7 @@ class AnthropicTokenCounter(TokenCounter):self._encoding: Any = Noneself._use_api = client is not None- if not self._use_api and not _FALLBACK_WARNING_SHOWN:+ if not self._use_api and warn and not _FALLBACK_WARNING_SHOWN:warnings.warn("AnthropicProvider: No client provided, using tiktoken approximation. ""For accurate counting, pass an Anthropic client: "@@ -446,6 +451,7 @@ class AnthropicProvider(Provider):self,client: Any = None,context_limits: dict[str, int] | None = None,+ warn: bool = True,):"""Initialize Anthropic provider.@@ -453,12 +459,16 @@ class AnthropicProvider(Provider):client: Optional anthropic.Anthropic client for accurate token counting.If not provided, uses tiktoken approximation.context_limits: Optional override for model context limits.+ warn: If False, suppresses the no-client UserWarning. Set to False+ in contexts where tiktoken approximation is intentional (e.g.+ the internal proxy pipeline provider).Example:from anthropic import Anthropicprovider = AnthropicProvider(client=Anthropic())"""self._client = client+ self._warn = warnself._token_counters: dict[str, AnthropicTokenCounter] = {}# Build context limits: defaults -> config file -> env var -> explicit@@ -488,6 +498,7 @@ class AnthropicProvider(Provider):self._token_counters[model] = AnthropicTokenCounter(model=model,client=self._client,+ warn=self._warn,)return self._token_counters[model]diff --git a/headroom/providers/litellm.py b/headroom/providers/litellm.pyindex 27508952a..cc374d5e6 100644--- a/headroom/providers/litellm.py+++ b/headroom/providers/litellm.py@@ -33,6 +33,12 @@ logger = logging.getLogger(__name__)# Check if litellm is availabletry:import litellm++ # Suppress litellm's startup banner ("Provider List: https://...") and+ # verbose debug output that spams stdout on every worker import.+ litellm.suppress_debug_info = True+ litellm.set_verbose = False+from litellm import get_model_info as litellm_get_model_infofrom litellm import model_cost as litellm_model_costfrom litellm import token_counter as litellm_token_counterdiff --git a/headroom/providers/registry.py b/headroom/providers/registry.pyindex 194273b92..1eff86be5 100644--- a/headroom/providers/registry.py+++ b/headroom/providers/registry.py@@ -126,7 +126,9 @@ def build_proxy_provider_runtime(config: Any) -> ProxyProviderRuntime:return ProxyProviderRuntime(api_targets=api_targets,pipeline_providers={- "anthropic": AnthropicProvider(),+ # warn=False: the proxy pipeline provider intentionally uses tiktoken+ # approximation (no Anthropic client available at this layer).+ "anthropic": AnthropicProvider(warn=False),"openai": OpenAIProvider(),},)diff --git a/headroom/transforms/html_extractor.py b/headroom/transforms/html_extractor.pyindex b14c1f431..2439a0e8a 100644--- a/headroom/transforms/html_extractor.py+++ b/headroom/transforms/html_extractor.py@@ -23,6 +23,11 @@ from typing import Anyimport trafilaturafrom trafilatura.settings import use_config+# Suppress trafilatura's internal parse-error noise (e.g. "parsed tree length: 0")+# which appears at WARNING level on every document that fails to extract content.+# These are expected failures for non-article pages; log them only at CRITICAL.+logging.getLogger("trafilatura").setLevel(logging.CRITICAL)+logger = logging.getLogger(__name__)diff --git a/headroom/transforms/kompress_compressor.py b/headroom/transforms/kompress_compressor.pyindex 38da597ee..c199cce0d 100644--- a/headroom/transforms/kompress_compressor.py+++ b/headroom/transforms/kompress_compressor.py@@ -25,7 +25,11 @@ from dataclasses import dataclassfrom typing import Any, Literalfrom ..config import TransformResult-from ..onnx_runtime import create_cpu_session_options, trim_process_heap+from ..onnx_runtime import (+ create_cpu_session_options,+ hf_hub_download_local_first,+ trim_process_heap,+)from ..tokenizer import Tokenizerfrom .base import Transform@@ -329,10 +333,9 @@ def _load_kompress_onnx(if model_id in _kompress_cache:return _kompress_cache[model_id]- from huggingface_hub import hf_hub_download-logger.info("Downloading Kompress ONNX model from %s ...", model_id)- onnx_path = hf_hub_download(model_id, "onnx/kompress-int8.onnx")++ onnx_path = hf_hub_download_local_first(model_id, "onnx/kompress-int8.onnx")backend = "onnx_coreml" if use_coreml else "onnx"providers: list[Any]@@ -383,10 +386,9 @@ def _load_kompress_pytorch(model_id: str, device: str = "auto") -> tuple[Any, Anif model_id in _kompress_cache:return _kompress_cache[model_id]- from huggingface_hub import hf_hub_download-logger.info("Downloading Kompress PyTorch model from %s ...", model_id)- weights_path = hf_hub_download(model_id, "model.safetensors")++ weights_path = hf_hub_download_local_first(model_id, "model.safetensors")HeadroomCompressorModel = _get_model_class()model = HeadroomCompressorModel()diff --git a/tests/test_startup_log_noise.py b/tests/test_startup_log_noise.pynew file mode 100644index 000000000..0da69ddeb--- /dev/null+++ b/tests/test_startup_log_noise.py@@ -0,0 +1,170 @@+"""Tests for startup log noise suppression.++Covers the fixes in:+- headroom/memory/adapters/embedders.py (HF env vars, httpx logger)+- headroom/providers/anthropic.py (warn=False suppresses tiktoken warning)+- headroom/providers/litellm.py (suppress_debug_info, set_verbose)+- headroom/transforms/html_extractor.py (trafilatura logger CRITICAL)+"""++from __future__ import annotations++import logging+import warnings+++class TestAnthropicWarnParameter:+ """AnthropicProvider.warn=False suppresses the no-client tiktoken warning."""++ def test_warn_true_emits_warning_without_client(self):+ """Default warn=True should emit UserWarning when no client is given."""+ import headroom.providers.anthropic as _mod+ from headroom.providers.anthropic import AnthropicProvider++ # Only runs if the module-level dedup flag hasn't fired yet in this process;+ # we reset it to guarantee the warning fires.++ original = _mod._FALLBACK_WARNING_SHOWN+ _mod._FALLBACK_WARNING_SHOWN = False+ try:+ with warnings.catch_warnings(record=True) as w:+ warnings.simplefilter("always")+ provider = AnthropicProvider(warn=True)+ # Trigger token-counter creation which is where warning fires+ try:+ provider.get_token_counter("claude-3-5-sonnet-20241022")+ except Exception:+ pass+ user_warnings = [x for x in w if issubclass(x.category, UserWarning)]+ assert any("tiktoken" in str(warning.message) for warning in user_warnings)+ finally:+ _mod._FALLBACK_WARNING_SHOWN = original++ def test_warn_false_suppresses_warning(self):+ """warn=False must produce zero UserWarnings about tiktoken fallback."""+ import headroom.providers.anthropic as _mod+ from headroom.providers.anthropic import AnthropicProvider++ original = _mod._FALLBACK_WARNING_SHOWN+ _mod._FALLBACK_WARNING_SHOWN = False+ try:+ with warnings.catch_warnings(record=True) as w:+ warnings.simplefilter("always")+ provider = AnthropicProvider(warn=False)+ try:+ provider.get_token_counter("claude-3-5-sonnet-20241022")+ except Exception:+ pass+ tiktoken_warnings = [+ x for x in w if issubclass(x.category, UserWarning) and "tiktoken" in str(x.message)+ ]+ assert tiktoken_warnings == [], (+ f"Expected no tiktoken warnings with warn=False, got: {tiktoken_warnings}"+ )+ finally:+ _mod._FALLBACK_WARNING_SHOWN = original++ def test_registry_uses_warn_false(self):+ """The internal proxy provider registry must pass warn=False to AnthropicProvider."""+ import inspect++ from headroom.providers import registry as _registry_mod++ source = inspect.getsource(_registry_mod)+ assert "AnthropicProvider(warn=False)" in source, (+ "registry.py must instantiate AnthropicProvider with warn=False"+ )+++class TestEmbedderLogLevels:+ """headroom.memory.adapters.embedders must set specific logger levels at import time."""++ def test_huggingface_hub_logger_is_error_or_higher(self):+ """huggingface_hub logger must be silenced to ERROR or above."""+ import headroom.memory.adapters.embedders # noqa: F401++ level = logging.getLogger("huggingface_hub").level+ assert level >= logging.ERROR, (+ f"Expected huggingface_hub logger level >= ERROR ({logging.ERROR}), got {level}"+ )++ def test_httpx_logger_is_warning_or_higher(self):+ """httpx logger must be set to WARNING or above to suppress HEAD request INFO lines."""+ import headroom.memory.adapters.embedders # noqa: F401++ level = logging.getLogger("httpx").level+ assert level >= logging.WARNING, (+ f"Expected httpx logger level >= WARNING ({logging.WARNING}), got {level}"+ )++ def test_hf_hub_env_vars_are_set(self):+ """HF Hub env vars to disable progress bars and implicit tokens must be set."""+ import os++ import headroom.memory.adapters.embedders # noqa: F401++ assert os.environ.get("HF_HUB_DISABLE_PROGRESS_BARS") == "1"+ assert os.environ.get("HF_HUB_DISABLE_IMPLICIT_TOKEN") == "1"+++class TestLiteLLMLogSuppression:+ """litellm startup banner suppression must be applied at import time."""++ def test_litellm_suppress_debug_info_is_set(self):+ """litellm.suppress_debug_info must be True after importing the litellm provider."""+ litellm = pytest_importorskip_litellm()+ if litellm is None:+ return # litellm not installed — skip gracefully++ import headroom.providers.litellm # noqa: F401++ assert litellm.suppress_debug_info is True, (+ "litellm.suppress_debug_info must be True to silence startup banner"+ )++ def test_litellm_set_verbose_is_false(self):+ """litellm.set_verbose must be False after importing the litellm provider."""+ litellm = pytest_importorskip_litellm()+ if litellm is None:+ return++ import headroom.providers.litellm # noqa: F401++ assert litellm.set_verbose is False, (+ "litellm.set_verbose must be False to suppress verbose debug output"+ )+++def pytest_importorskip_litellm():+ """Return litellm if installed, else None (for graceful skip in optional-dep tests)."""+ try:+ import litellm++ return litellm+ except ImportError:+ return None+++class TestTrafilaturaLogLevel:+ """trafilatura logger must be raised to CRITICAL to suppress parse-error noise."""++ def test_trafilatura_logger_is_critical(self):+ """trafilatura logger must be CRITICAL or above after importing html_extractor."""+ pytest_importorskip_trafilatura()++ import headroom.transforms.html_extractor # noqa: F401++ level = logging.getLogger("trafilatura").level+ assert level >= logging.CRITICAL, (+ f"Expected trafilatura logger level >= CRITICAL ({logging.CRITICAL}), got {level}"+ )+++def pytest_importorskip_trafilatura():+ """Skip test if trafilatura is not installed."""+ try:+ import trafilatura # noqa: F401+ except ImportError:+ import pytest++ pytest.skip("trafilatura not installed")