{"record":{"id":"91be094292661a25","repo":"crewAIInc/crewAI","slug":"scrapegraph-api-key-is-required","errorCode":null,"errorMessage":"Scrapegraph API key is required","messagePattern":"Scrapegraph API key is required","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"lib/crewai-tools/src/crewai_tools/tools/scrapegraph_scrape_tool/scrapegraph_scrape_tool.py","lineNumber":117,"sourceCode":"            ):\n                import subprocess\n\n                subprocess.run([\"uv\", \"add\", \"scrapegraph-py\"], check=True)  # noqa: S607\n                from scrapegraph_py import Client  # type: ignore[import-untyped]\n                from scrapegraph_py.logger import (  # type: ignore[import-untyped]\n                    sgai_logger,\n                )\n\n            else:\n                raise ImportError(\n                    \"`scrapegraph-py` package not found, please run `uv add scrapegraph-py`\"\n                ) from None\n\n        self.api_key = api_key or os.getenv(\"SCRAPEGRAPH_API_KEY\")\n        self._client = Client(api_key=self.api_key)\n\n        if not self.api_key:\n            raise ValueError(\"Scrapegraph API key is required\")\n\n        if website_url is not None:\n            self._validate_url(website_url)\n            self.website_url = website_url\n            self.description = f\"A tool that uses Scrapegraph AI to intelligently scrape {website_url}'s content.\"\n            self.args_schema = FixedScrapegraphScrapeToolSchema\n\n        if user_prompt is not None:\n            self.user_prompt = user_prompt\n\n        if self.enable_logging:\n            sgai_logger.set_logging(level=\"INFO\")\n\n    @staticmethod\n    def _validate_url(url: str) -> None:\n        \"\"\"Validate URL format.\"\"\"\n        try:\n            result = urlparse(url)","sourceCodeStart":99,"sourceCodeEnd":135,"githubUrl":"https://github.com/crewAIInc/crewAI/blob/754d7323beb2fd042e33444a115ea2d5a47193f0/lib/crewai-tools/src/crewai_tools/tools/scrapegraph_scrape_tool/scrapegraph_scrape_tool.py#L99-L135","documentation":"Raised by ScrapegraphScrapeTool's constructor when neither an api_key argument nor the SCRAPEGRAPH_API_KEY environment variable yields a key. Note the source order: self.api_key is resolved, a Client is constructed with it, and only then is the emptiness check performed — so the check fires after client creation but before the tool becomes usable.","triggerScenarios":"ScrapegraphScrapeTool() (or with website_url) created while SCRAPEGRAPH_API_KEY is unset/empty and no api_key argument is given — common in fresh shells, CI, or when the key was exported in a different terminal session.","commonSituations":"Forgot to export SCRAPEGRAPH_API_KEY; key stored in an unloaded .env file; environment-specific shells (direnv not activated); typo in the variable name.","solutions":["Set the environment variable: export SCRAPEGRAPH_API_KEY=your_key, then rerun","Or pass it explicitly: ScrapegraphScrapeTool(api_key='your_key')","Load your .env before tool construction (load_dotenv()) and verify with os.environ.get('SCRAPEGRAPH_API_KEY')","Get a key from the Scrapegraph AI dashboard if you don't have one yet"],"exampleFix":"# before\ntool = ScrapegraphScrapeTool()  # ValueError: API key is required\n\n# after\nimport os\ntool = ScrapegraphScrapeTool(api_key=os.environ['SCRAPEGRAPH_API_KEY'])\n","handlingStrategy":"validation","validationCode":"import os\n\ndef has_scrapegraph_key() -> bool:\n    return bool(os.environ.get(\"SCRAPEGRAPH_API_KEY\"))\n\nassert has_scrapegraph_key(), \"Set SCRAPEGRAPH_API_KEY or pass api_key=\"","typeGuard":null,"tryCatchPattern":"try:\n    tool = ScrapegraphScrapeTool(api_key=os.environ.get(\"SCRAPEGRAPH_API_KEY\"))\nexcept ValueError as e:\n    if \"API key\" in str(e):\n        raise SystemExit(\"Missing SCRAPEGRAPH_API_KEY — get one at scrapegraph.ai and export it\") from e\n    raise","preventionTips":["Export SCRAPEGRAPH_API_KEY in your shell profile/CI secrets","Pass api_key explicitly in scripts to avoid ambient-env dependence","load_dotenv() at startup and assert the key exists before building agents","Note the Client is constructed before the key check — never instantiate with a known-empty key"],"tags":["credentials","api-key","configuration","environment-variables","scrapegraph"],"backgroundTag":null,"analyzedSha":"754d7323beb2fd042e33444a115ea2d5a47193f0","analyzedAt":"2026-08-15T04:06:56.746Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}