crewAIInc/crewAI · error · ValueError
project_id is required (or set BROWSERBASE_PROJECT_ID in env
Error message
project_id is required (or set BROWSERBASE_PROJECT_ID in env.)
What it means
StagehandTool requires a Browserbase project ID alongside the API key. _check_required_credentials resolves project_id from the constructor or the BROWSERBASE_PROJECT_ID env var and raises ValueError when neither is set. The project ID scopes sessions to a specific Browserbase project (its browser settings, proxies, and quotas).
Source
Thrown at lib/crewai-tools/src/crewai_tools/tools/stagehand_tool/stagehand_tool.py:248
if not self._testing:
log_level = {1: "INFO", 2: "WARNING", 3: "DEBUG"}.get(self.verbose, "ERROR")
configure_logging(
level=log_level, remove_logger_name=True, quiet_dependencies=True
)
self._check_required_credentials()
def _check_required_credentials(self) -> None:
"""Validate that required credentials are present."""
if not self._testing and not _HAS_STAGEHAND:
raise ImportError(
"`stagehand` package not found, please run `uv add stagehand`"
)
if not self.api_key:
raise ValueError("api_key is required (or set BROWSERBASE_API_KEY in env).")
if not self.project_id:
raise ValueError(
"project_id is required (or set BROWSERBASE_PROJECT_ID in env)."
)
def __del__(self) -> None:
"""Ensure cleanup on deletion."""
try:
self.close()
except Exception: # noqa: S110
pass
def _get_model_api_key(self) -> str | None:
"""Get the appropriate API key based on the model being used."""
model_str = str(self.model_name)
if "gpt" in model_str.lower():
return self.model_api_key or os.getenv("OPENAI_API_KEY")
if "claude" in model_str.lower() or "anthropic" in model_str.lower():
return self.model_api_key or os.getenv("ANTHROPIC_API_KEY")
if "gemini" in model_str.lower():View on GitHub (pinned to 754d7323be)
Solutions
- Set export BROWSERBASE_PROJECT_ID=your_project_id (both values are shown together on the Browserbase dashboard).
- Or pass it explicitly: StagehandTool(api_key=..., project_id=...).
- Audit your .env / CI secret injection to confirm both BROWSERBASE_API_KEY and BROWSERBASE_PROJECT_ID reach the process.
Example fix
# .env # before BROWSERBASE_API_KEY=xxx # after BROWSERBASE_API_KEY=xxx BROWSERBASE_PROJECT_ID=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
Defensive patterns
Strategy: validation
Validate before calling
import os
project_id = os.environ.get("BROWSERBASE_PROJECT_ID") or provided_project_id
if not project_id:
raise ValueError("Set BROWSERBASE_PROJECT_ID or pass project_id= to StagehandTool") Type guard
def has_browserbase_project_id(project_id: str | None) -> bool:
return bool(project_id or os.environ.get("BROWSERBASE_PROJECT_ID")) Try / catch
try:
tool = StagehandTool()
except ValueError as e:
if "project_id is required" in str(e):
raise RuntimeError("Missing BROWSERBASE_PROJECT_ID; copy it from the Browserbase dashboard") from e
raise Prevention
- Store both BROWSERBASE_API_KEY and BROWSERBASE_PROJECT_ID together in .env/CI secrets.
- Smoke-test at deploy time that both env vars resolve to non-empty strings.
When it happens
Trigger: StagehandTool(api_key=...) with project_id omitted and BROWSERBASE_PROJECT_ID unset; copying the API key but not the project ID from the Browserbase dashboard; env vars set in one shell but the process launched from another (or via a service file) without them.
Common situations: New Browserbase accounts that created a key but overlooked the project ID; deployment manifests that inject only one of the two secrets; local runs where the second env var line was missed in .env.
Related errors
- api_key is required (or set BROWSERBASE_API_KEY in env).
- You must pass oxylabs username and password when instantiati
- You must pass oxylabs username and password when instantiati
- You must pass oxylabs username and password when instantiati
- You must pass oxylabs username and password when instantiati
AI-assisted analysis of crewAIInc/crewAI@754d7323be (2026-08-15).
Data as JSON: /api/errors/2d4543a8564d91f5.
Report an issue: GitHub.