crewAIInc/crewAI · error · ValueError
HYPERBROWSER_API_KEY is not set. Please provide it either vi
Error message
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.
What it means
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.
Source
Thrown at lib/crewai-tools/src/crewai_tools/tools/hyperbrowser_load_tool/hyperbrowser_load_tool.py:63
)
def __init__(self, api_key: str | None = None, **kwargs: Any) -> None:
super().__init__(**kwargs)
self.api_key = api_key or os.getenv("HYPERBROWSER_API_KEY")
if not api_key:
raise ValueError(
"`api_key` is required, please set the `HYPERBROWSER_API_KEY` environment variable or pass it directly"
)
try:
from hyperbrowser import Hyperbrowser # type: ignore[import-untyped]
except ImportError as e:
raise ImportError(
"`hyperbrowser` package not found, please run `pip install hyperbrowser`"
) from e
if not self.api_key:
raise ValueError(
"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."
)
self.hyperbrowser = Hyperbrowser(api_key=self.api_key)
@staticmethod
def _prepare_params(params: dict[str, Any]) -> dict[str, Any]:
"""Prepare session and scrape options parameters."""
try:
from hyperbrowser.models.scrape import ( # type: ignore[import-untyped]
ScrapeOptions,
)
from hyperbrowser.models.session import ( # type: ignore[import-untyped]
CreateSessionParams,
)
except ImportError as e:
raise ImportError(
"`hyperbrowser` package not found, please run `pip install hyperbrowser`"View on GitHub (pinned to 754d7323be)
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).
Example fix
# consolidation fix in library
- if not api_key:
- raise ValueError("`api_key` is required, ...")
...
- if not self.api_key:
- raise ValueError("HYPERBROWSER_API_KEY is not set. ...")
+ if not self.api_key:
+ raise ValueError("`api_key` is required: pass it or set HYPERBROWSER_API_KEY") Defensive patterns
Strategy: validation
Validate before calling
api_key = api_key_arg or os.getenv('HYPERBROWSER_API_KEY')
if not api_key:
raise SystemExit('HYPERBROWSER_API_KEY missing')
tool = HyperbrowserLoadTool(api_key=api_key) Try / catch
try:
tool = HyperbrowserLoadTool(api_key=KEY)
except ValueError as e:
if 'HYPERBROWSER_API_KEY' in str(e) or 'api_key' in str(e):
raise SystemExit('provide the API key via arg or env') from e
raise Prevention
- Treat both near-duplicate key errors the same: supply the key explicitly.
- If patching the library, keep a single guard on self.api_key.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- `api_key` is required, please set the `HYPERBROWSER_API_KEY`
- API key must be provided either through constructor or MINDS
- BRAVE_API_KEY environment variable is required for BraveSear
- BRIGHT_DATA_API_KEY environment variable is required.
- AGENT_HANDLER_API_KEY environment variable is required. Set
AI-assisted analysis of crewAIInc/crewAI@754d7323be (2026-08-15).
Data as JSON: /api/errors/851aa41bfecc6e04.
Report an issue: GitHub.