{"record":{"id":"2d4543a8564d91f5","repo":"crewAIInc/crewAI","slug":"project-id-is-required-or-set-browserbase-project","errorCode":null,"errorMessage":"project_id is required (or set BROWSERBASE_PROJECT_ID in env.)","messagePattern":"project_id is required \\(or set BROWSERBASE_PROJECT_ID in env\\.\\)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"lib/crewai-tools/src/crewai_tools/tools/stagehand_tool/stagehand_tool.py","lineNumber":248,"sourceCode":"        if not self._testing:\n            log_level = {1: \"INFO\", 2: \"WARNING\", 3: \"DEBUG\"}.get(self.verbose, \"ERROR\")\n            configure_logging(\n                level=log_level, remove_logger_name=True, quiet_dependencies=True\n            )\n\n        self._check_required_credentials()\n\n    def _check_required_credentials(self) -> None:\n        \"\"\"Validate that required credentials are present.\"\"\"\n        if not self._testing and not _HAS_STAGEHAND:\n            raise ImportError(\n                \"`stagehand` package not found, please run `uv add stagehand`\"\n            )\n\n        if not self.api_key:\n            raise ValueError(\"api_key is required (or set BROWSERBASE_API_KEY in env).\")\n        if not self.project_id:\n            raise ValueError(\n                \"project_id is required (or set BROWSERBASE_PROJECT_ID in env).\"\n            )\n\n    def __del__(self) -> None:\n        \"\"\"Ensure cleanup on deletion.\"\"\"\n        try:\n            self.close()\n        except Exception:  # noqa: S110\n            pass\n\n    def _get_model_api_key(self) -> str | None:\n        \"\"\"Get the appropriate API key based on the model being used.\"\"\"\n        model_str = str(self.model_name)\n        if \"gpt\" in model_str.lower():\n            return self.model_api_key or os.getenv(\"OPENAI_API_KEY\")\n        if \"claude\" in model_str.lower() or \"anthropic\" in model_str.lower():\n            return self.model_api_key or os.getenv(\"ANTHROPIC_API_KEY\")\n        if \"gemini\" in model_str.lower():","sourceCodeStart":230,"sourceCodeEnd":266,"githubUrl":"https://github.com/crewAIInc/crewAI/blob/754d7323beb2fd042e33444a115ea2d5a47193f0/lib/crewai-tools/src/crewai_tools/tools/stagehand_tool/stagehand_tool.py#L230-L266","documentation":"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).","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"# .env\n# before\nBROWSERBASE_API_KEY=xxx\n\n# after\nBROWSERBASE_API_KEY=xxx\nBROWSERBASE_PROJECT_ID=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx","handlingStrategy":"validation","validationCode":"import os\nproject_id = os.environ.get(\"BROWSERBASE_PROJECT_ID\") or provided_project_id\nif not project_id:\n    raise ValueError(\"Set BROWSERBASE_PROJECT_ID or pass project_id= to StagehandTool\")","typeGuard":"def has_browserbase_project_id(project_id: str | None) -> bool:\n    return bool(project_id or os.environ.get(\"BROWSERBASE_PROJECT_ID\"))","tryCatchPattern":"try:\n    tool = StagehandTool()\nexcept ValueError as e:\n    if \"project_id is required\" in str(e):\n        raise RuntimeError(\"Missing BROWSERBASE_PROJECT_ID; copy it from the Browserbase dashboard\") from e\n    raise","preventionTips":["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."],"tags":["stagehand","browserbase","credentials","configuration"],"backgroundTag":null,"analyzedSha":"754d7323beb2fd042e33444a115ea2d5a47193f0","analyzedAt":"2026-08-15T04:06:56.746Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}