{"record":{"id":"6a67890ecaea9431","repo":"headroomlabs-ai/headroom","slug":"openai-package-required-install-with-pip-install-6a6789","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/runners/before_after.py","lineNumber":114,"sourceCode":"\n    def _init_llm_client(self) -> Any:\n        \"\"\"Initialize the appropriate LLM client.\"\"\"\n        if self.llm_config.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.llm_config.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        elif self.llm_config.provider == \"ollama\":\n            try:\n                import ollama\n\n                return ollama.Client()\n            except ImportError as e:\n                raise ImportError(\n                    \"ollama package required. Install with: pip install ollama\"\n                ) from e\n        else:\n            raise ValueError(f\"Unknown provider: {self.llm_config.provider}\")\n\n    def _init_proxy_client(self) -> Any:\n        \"\"\"Initialize an OpenAI client pointing at the Headroom proxy.\"\"\"\n        import openai\n","sourceCodeStart":96,"sourceCodeEnd":132,"githubUrl":"https://github.com/headroomlabs-ai/headroom/blob/322425c43bffde1ed0b64fecf3cf5951565dd82b/headroom/evals/runners/before_after.py#L96-L132","documentation":"Raised by BeforeAfterRunner._init_llm_client when llm_config.provider == 'openai' but the openai SDK is not installed. Like the other provider branches, the import is deferred until the LLM judge is first needed, so the error surfaces mid-run. Note this specific error is about the DIRECT OpenAI path — the proxy path (_init_proxy_client) imports openai unconditionally and would fail with a plain ImportError instead.","triggerScenarios":"provider='openai' in the before/after runner's LLM config while the active environment lacks the openai package; common when the eval suite was installed with only some provider extras, or the run happens in a fresh tox/nox env.","commonSituations":"Minimal eval installs; mixing system Python and a project venv; CI matrices that skip the openai extra on some jobs; stale lockfiles after the provider list changed.","solutions":["python -m pip install openai in the interpreter running the eval.","Or add the openai extra / eval extra to your project install so CI always has it.","If you meant to go through the Headroom proxy instead of direct OpenAI, configure the proxy path so no direct provider SDK is needed.","Check: python -c \"import openai; print(openai.__version__)\"."],"exampleFix":"# before\n# provider=\"openai\" with no SDK -> ImportError: openai package required\n\n# after\n$ python -m pip install openai\n# and keep OPENAI_API_KEY exported for the judge","handlingStrategy":"validation","validationCode":"import importlib.util\n\nif importlib.util.find_spec(\"openai\") is None:\n    raise SystemExit(\"openai SDK missing — run: pip install openai\")","typeGuard":null,"tryCatchPattern":"try:\n    runner.run()\nexcept ImportError as e:\n    if \"openai package required\" in str(e):\n        sys.exit(\"Install openai, or set provider='ollama'/'anthropic' if that's your stack\")\n    raise","preventionTips":["Pre-flight check provider SDK availability per suite config before launching long runs.","Keep provider deps in the same requirements set as headroom evals.","Remember the Headroom-proxy path also needs openai — install it if you use either direct or proxy mode."],"tags":["openai","import-error","optional-dependency","evals","configuration"],"backgroundTag":null,"analyzedSha":"322425c43bffde1ed0b64fecf3cf5951565dd82b","analyzedAt":"2026-08-15T01:03:05.481Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}