{"record":{"id":"7d46c6214b28292a","repo":"crewAIInc/crewAI","slug":"api-key-is-required-please-set-the-hyperbrowse","errorCode":null,"errorMessage":"`api_key` is required, please set the `HYPERBROWSER_API_KEY` environment variable or pass it directly","messagePattern":"`api_key` is required, please set the `HYPERBROWSER_API_KEY` environment variable or pass it directly","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"lib/crewai-tools/src/crewai_tools/tools/hyperbrowser_load_tool/hyperbrowser_load_tool.py","lineNumber":51,"sourceCode":"    args_schema: type[BaseModel] = HyperbrowserLoadToolSchema\n    api_key: str | None = None\n    hyperbrowser: Any | None = None\n    package_dependencies: list[str] = Field(default_factory=lambda: [\"hyperbrowser\"])\n    env_vars: list[EnvVar] = Field(\n        default_factory=lambda: [\n            EnvVar(\n                name=\"HYPERBROWSER_API_KEY\",\n                description=\"API key for Hyperbrowser services\",\n                required=False,\n            ),\n        ]\n    )\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","sourceCodeStart":33,"sourceCodeEnd":69,"githubUrl":"https://github.com/crewAIInc/crewAI/blob/754d7323beb2fd042e33444a115ea2d5a47193f0/lib/crewai-tools/src/crewai_tools/tools/hyperbrowser_load_tool/hyperbrowser_load_tool.py#L33-L69","documentation":"ValueError raised in HyperbrowserLoadTool.__init__ when the constructor's api_key argument is falsy. NOTE THE BUG: the guard tests the local parameter 'api_key', not self.api_key (which already merged in HYPERBROWSER_API_KEY from the environment). So even when the env var IS set, omitting the constructor argument still raises — the documented env-variable fallback is unreachable past this line.","triggerScenarios":"Calling HyperbrowserLoadTool() with no api_key argument, relying on the HYPERBROWSER_API_KEY environment variable as the docs suggest — this raises despite the env var being set. Only an explicit api_key='...' (or a truthy env var AND... no, the check ignores self.api_key entirely) passes; actually any falsy constructor arg triggers it.","commonSituations":"Users following the EnvVar description and setting HYPERBROWSER_API_KEY in .env, then instantiating with no args and hitting a spurious error; deployments that inject secrets exclusively via environment variables.","solutions":["Pass the key explicitly: HyperbrowserLoadTool(api_key=os.environ['HYPERBROWSER_API_KEY']).","Or fix the library guard: change 'if not api_key:' to 'if not self.api_key:' so the env-var fallback works.","Double-check the env var name spelling (HYPERBROWSER_API_KEY) if you patch the guard."],"exampleFix":"# before\nos.environ['HYPERBROWSER_API_KEY'] = 'hb_...'\ntool = HyperbrowserLoadTool()  # raises: guard checks the param, not self.api_key\n\n# after\ntool = HyperbrowserLoadTool(api_key=os.environ['HYPERBROWSER_API_KEY'])\n\n# library fix:\n- if not api_key:\n+ if not self.api_key:","handlingStrategy":"validation","validationCode":"api_key = os.getenv('HYPERBROWSER_API_KEY')\nif not api_key:\n    raise SystemExit('set HYPERBROWSER_API_KEY or pass api_key=')\ntool = HyperbrowserLoadTool(api_key=api_key)  # pass explicitly; env-only path is buggy","typeGuard":null,"tryCatchPattern":"try:\n    tool = HyperbrowserLoadTool(api_key=os.getenv('HYPERBROWSER_API_KEY'))\nexcept ValueError as e:\n    if 'api_key' in str(e):\n        raise SystemExit('provide HYPERBROWSER_API_KEY explicitly') from e\n    raise","preventionTips":["Always pass api_key explicitly to Hyperbrowser tools; do not rely on the env-only path.","If you maintain a fork, fix the guard to check self.api_key instead of the parameter.","Validate required secrets at app startup, not at tool call time."],"tags":["hyperbrowser","api-key","configuration","env-var","library-bug"],"backgroundTag":null,"analyzedSha":"754d7323beb2fd042e33444a115ea2d5a47193f0","analyzedAt":"2026-08-15T04:06:56.746Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}