{"record":{"id":"851aa41bfecc6e04","repo":"crewAIInc/crewAI","slug":"hyperbrowser-api-key-is-not-set-please-provide-it","errorCode":null,"errorMessage":"HYPERBROWSER_API_KEY is not set. Please provide it either via the constructor with the `api_key` argument or by setting the HYPERBROWSER_API_KEY environment variable.","messagePattern":"HYPERBROWSER_API_KEY is not set\\. Please provide it either via the constructor with the `api_key` argument or by setting the HYPERBROWSER_API_KEY environment variable\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"lib/crewai-tools/src/crewai_tools/tools/hyperbrowser_load_tool/hyperbrowser_load_tool.py","lineNumber":63,"sourceCode":"    )\n\n    def __init__(self, api_key: str | None = None, **kwargs: Any) -> None:\n        super().__init__(**kwargs)\n        self.api_key = api_key or os.getenv(\"HYPERBROWSER_API_KEY\")\n        if not api_key:\n            raise ValueError(\n                \"`api_key` is required, please set the `HYPERBROWSER_API_KEY` environment variable or pass it directly\"\n            )\n\n        try:\n            from hyperbrowser import Hyperbrowser  # type: ignore[import-untyped]\n        except ImportError as e:\n            raise ImportError(\n                \"`hyperbrowser` package not found, please run `pip install hyperbrowser`\"\n            ) from e\n\n        if not self.api_key:\n            raise ValueError(\n                \"HYPERBROWSER_API_KEY is not set. Please provide it either via the constructor with the `api_key` argument or by setting the HYPERBROWSER_API_KEY environment variable.\"\n            )\n\n        self.hyperbrowser = Hyperbrowser(api_key=self.api_key)\n\n    @staticmethod\n    def _prepare_params(params: dict[str, Any]) -> dict[str, Any]:\n        \"\"\"Prepare session and scrape options parameters.\"\"\"\n        try:\n            from hyperbrowser.models.scrape import (  # type: ignore[import-untyped]\n                ScrapeOptions,\n            )\n            from hyperbrowser.models.session import (  # type: ignore[import-untyped]\n                CreateSessionParams,\n            )\n        except ImportError as e:\n            raise ImportError(\n                \"`hyperbrowser` package not found, please run `pip install hyperbrowser`\"","sourceCodeStart":45,"sourceCodeEnd":81,"githubUrl":"https://github.com/crewAIInc/crewAI/blob/754d7323beb2fd042e33444a115ea2d5a47193f0/lib/crewai-tools/src/crewai_tools/tools/hyperbrowser_load_tool/hyperbrowser_load_tool.py#L45-L81","documentation":"Second api-key ValueError in HyperbrowserLoadTool.__init__ ('if not self.api_key'). It is effectively DEAD CODE: the earlier 'if not api_key:' guard (which checks the constructor parameter) already raised for every case where the parameter is falsy, and when the parameter is truthy self.api_key is truthy too. You should never see this message in practice; if you do, the earlier guard was modified.","triggerScenarios":"Theoretically reachable only if the first guard is removed/changed (e.g. a patched library fixing error 375 to check self.api_key while api_key came solely from an unset env var). With the shipped code, no input reaches it.","commonSituations":"Local forks of crewai-tools where the first guard was fixed but the env var is still missing; confusion because the duplicate messages differ and search results point here.","solutions":["Set HYPERBROWSER_API_KEY in the environment or pass api_key=... to the constructor.","If maintaining a fork, keep only one guard: if not self.api_key: raise ... (remove the duplicate)."],"exampleFix":"# consolidation fix in library\n- if not api_key:\n-     raise ValueError(\"`api_key` is required, ...\")\n  ...\n- if not self.api_key:\n-     raise ValueError(\"HYPERBROWSER_API_KEY is not set. ...\")\n+ if not self.api_key:\n+     raise ValueError(\"`api_key` is required: pass it or set HYPERBROWSER_API_KEY\")","handlingStrategy":"validation","validationCode":"api_key = api_key_arg or os.getenv('HYPERBROWSER_API_KEY')\nif not api_key:\n    raise SystemExit('HYPERBROWSER_API_KEY missing')\ntool = HyperbrowserLoadTool(api_key=api_key)","typeGuard":null,"tryCatchPattern":"try:\n    tool = HyperbrowserLoadTool(api_key=KEY)\nexcept ValueError as e:\n    if 'HYPERBROWSER_API_KEY' in str(e) or 'api_key' in str(e):\n        raise SystemExit('provide the API key via arg or env') from e\n    raise","preventionTips":["Treat both near-duplicate key errors the same: supply the key explicitly.","If patching the library, keep a single guard on self.api_key."],"tags":["hyperbrowser","api-key","dead-code","configuration"],"backgroundTag":null,"analyzedSha":"754d7323beb2fd042e33444a115ea2d5a47193f0","analyzedAt":"2026-08-15T04:06:56.746Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}