{"record":{"id":"c8c0564ec84564c6","repo":"headroomlabs-ai/headroom","slug":"openai-package-required-install-with-pip-install","errorCode":null,"errorMessage":"openai package required. Install with: pip install openai","messagePattern":"openai package required\\. Install with: pip install openai","errorType":"exception","errorClass":"ImportError","httpStatus":null,"severity":"error","filePath":"headroom/evals/batch_compression_eval.py","lineNumber":1047,"sourceCode":"\n    def _init_llm_client(self) -> Any:\n        \"\"\"Initialize LLM client.\"\"\"\n        if self.provider == \"anthropic\":\n            try:\n                import anthropic\n\n                return anthropic.Anthropic()\n            except ImportError as e:\n                raise ImportError(\n                    \"anthropic package required. Install with: pip install anthropic\"\n                ) from e\n        elif self.provider == \"openai\":\n            try:\n                import openai\n\n                return openai.OpenAI()\n            except ImportError as e:\n                raise ImportError(\n                    \"openai package required. Install with: pip install openai\"\n                ) from e\n        else:\n            raise ValueError(f\"Unknown provider: {self.provider}\")\n\n    def _call_llm(self, messages: list[dict[str, Any]]) -> str:\n        \"\"\"Call LLM and return response text.\"\"\"\n        if self.provider == \"anthropic\":\n            response = self._llm_client.messages.create(\n                model=self.model,\n                max_tokens=1024,\n                temperature=0.0,\n                messages=messages,\n            )\n            return str(response.content[0].text)\n        elif self.provider == \"openai\":\n            response = self._llm_client.chat.completions.create(\n                model=self.model,","sourceCodeStart":1029,"sourceCodeEnd":1065,"githubUrl":"https://github.com/headroomlabs-ai/headroom/blob/322425c43bffde1ed0b64fecf3cf5951565dd82b/headroom/evals/batch_compression_eval.py#L1029-L1065","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["pip install openapi into the running interpreter: `pip install openai`","Confirm `python -c \"import openai\"` works in the exact env (watch for pip-vs-python mismatch)","Set OPENAI_API_KEY (or the proxy base URL + key) before running, since client init is immediately followed by API calls"],"exampleFix":"# before\nrunner = BatchCompressionEval(provider=\"openai\", ...)\n# ImportError: openai package required.\n\n# after\n# pip install openai\n# export OPENAI_API_KEY=sk-...\nrunner = BatchCompressionEval(provider=\"openai\", ...)","handlingStrategy":"validation","validationCode":"try:\n    import openai  # noqa: F401\nexcept ImportError:\n    raise SystemExit(\"Eval requires the openai SDK: pip install openai\")","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Install the openai SDK before running provider='openai' evals","Use one virtualenv for headroom evals and its LLM SDKs to avoid interpreter drift","Smoke-test the import in CI for every provider the matrix exercises"],"tags":["dependency","import","evals","openai","llm"],"backgroundTag":null,"analyzedSha":"322425c43bffde1ed0b64fecf3cf5951565dd82b","analyzedAt":"2026-08-15T01:03:05.481Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}