headroomlabs-ai/headroom · error · ImportError

anthropic package required. Install with: pip install anthro

Error message

anthropic package required. Install with: pip install anthropic

What it means

Raised by _init_llm_client() in the batch compression eval harness when provider == 'anthropic' but `import anthropic` fails. The eval driver lazy-imports the SDK only for the selected provider and converts ImportError into a targeted message; it is chained (`from e`) so the true import failure (not installed, wrong interpreter, or broken install) stays visible in the traceback.

Source

Thrown at headroom/evals/batch_compression_eval.py:1038

        self._token_counter = TokenCounter(self.model)
        self._llm_client = self._init_llm_client()

    def _get_default_model(self, provider: str) -> str:
        """Get default model for provider."""
        return {
            "anthropic": "claude-sonnet-4-20250514",
            "openai": "gpt-4o",
        }.get(provider, "claude-sonnet-4-20250514")

    def _init_llm_client(self) -> Any:
        """Initialize LLM client."""
        if self.provider == "anthropic":
            try:
                import anthropic

                return anthropic.Anthropic()
            except ImportError as e:
                raise ImportError(
                    "anthropic package required. Install with: pip install anthropic"
                ) from e
        elif self.provider == "openai":
            try:
                import openai

                return openai.OpenAI()
            except ImportError as e:
                raise ImportError(
                    "openai package required. Install with: pip install openai"
                ) from e
        else:
            raise ValueError(f"Unknown provider: {self.provider}")

    def _call_llm(self, messages: list[dict[str, Any]]) -> str:
        """Call LLM and return response text."""
        if self.provider == "anthropic":
            response = self._llm_client.messages.create(

View on GitHub (pinned to 322425c43b)

Solutions

  1. pip install anthropic into the interpreter running the evals
  2. Verify with `python -c "import anthropic"` in that same environment; fix venv/interpreter mismatch if it fails
  3. Ensure ANTHROPIC_API_KEY is set too — the import will succeed but anthropic.Anthropic() will be the next failure without it

Example fix

# before
runner = BatchCompressionEval(provider="anthropic", ...)
# ImportError: anthropic package required.

# after
# pip install anthropic
# export ANTHROPIC_API_KEY=sk-ant-...
runner = BatchCompressionEval(provider="anthropic", ...)
Defensive patterns

Strategy: validation

Validate before calling

try:
    import anthropic  # noqa: F401
except ImportError:
    raise SystemExit("Eval requires the anthropic SDK: pip install anthropic")

Prevention

When it happens

Trigger: Constructing the batch-compression eval driver with provider='anthropic' in an environment lacking the anthropic package. Note the constructor also defaults the model to claude-sonnet-4-20250514 for this provider, so merely selecting the provider without the SDK installed triggers it at client init.

Common situations: headroom installed without the anthropic extra; evals run under the system Python while anthropic was pip-installed in a venv; broken anthropic install (missing transitive deps like httpx) also surfaces here as ImportError.

Related errors


AI-assisted analysis of headroomlabs-ai/headroom@322425c43b (2026-08-15). Data as JSON: /api/errors/09a58d51e4431fdd. Report an issue: GitHub.