headroomlabs-ai/headroom · error · ImportError

openai package required. Install with: pip install openai

Error message

openai package required. Install with: pip install openai

What it means

Sibling of the anthropic guard in the same _init_llm_client(): when provider == 'openai', `import openai` must succeed or ImportError is raised with install instructions. The eval harness needs the OpenAI SDK to instantiate openai.OpenAI() for _call_llm's chat.completions calls against the configured base URL.

Source

Thrown at headroom/evals/batch_compression_eval.py:1047

    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(
                model=self.model,
                max_tokens=1024,
                temperature=0.0,
                messages=messages,
            )
            return str(response.content[0].text)
        elif self.provider == "openai":
            response = self._llm_client.chat.completions.create(
                model=self.model,

View on GitHub (pinned to 322425c43b)

Solutions

  1. pip install openapi into the running interpreter: `pip install openai`
  2. Confirm `python -c "import openai"` works in the exact env (watch for pip-vs-python mismatch)
  3. Set OPENAI_API_KEY (or the proxy base URL + key) before running, since client init is immediately followed by API calls

Example fix

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

# after
# pip install openai
# export OPENAI_API_KEY=sk-...
runner = BatchCompressionEval(provider="openai", ...)
Defensive patterns

Strategy: validation

Validate before calling

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

Prevention

When it happens

Trigger: Running the batch compression eval with provider='openai' (model defaults to gpt-4o) where the openai package is absent or unimportable in the active interpreter.

Common situations: Fresh checkout running evals without the LLM extras; mixed interpreters (tool installed via pipx, openai installed via system pip); upgrading Python versions and forgetting to reinstall SDKs.

Related errors


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