{"record":{"id":"8e03824adbfe8f57","repo":"crewAIInc/crewAI","slug":"bright-data-api-key-environment-variable-is-requir","errorCode":null,"errorMessage":"BRIGHT_DATA_API_KEY environment variable is required.","messagePattern":"BRIGHT_DATA_API_KEY environment variable is required\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"critical","filePath":"lib/crewai-tools/src/crewai_tools/tools/brightdata_tool/brightdata_dataset.py","lineNumber":580,"sourceCode":"        zipcode = zipcode or self.zipcode\n        additional_params = additional_params or self.additional_params\n\n        if not dataset_type:\n            raise ValueError(\n                \"dataset_type is required either in constructor or method call\"\n            )\n        if not url:\n            raise ValueError(\"url is required either in constructor or method call\")\n\n        valid_output_formats = {\"json\", \"ndjson\", \"jsonl\", \"csv\"}\n        if output_format not in valid_output_formats:\n            raise ValueError(\n                f\"Unsupported output format: {output_format}. Must be one of {', '.join(valid_output_formats)}.\"\n            )\n\n        api_key = os.getenv(\"BRIGHT_DATA_API_KEY\")\n        if not api_key:\n            raise ValueError(\"BRIGHT_DATA_API_KEY environment variable is required.\")\n\n        try:\n            return asyncio.run(\n                self.get_dataset_data_async(\n                    dataset_type=dataset_type,\n                    output_format=output_format,\n                    url=url,\n                    zipcode=zipcode,\n                    additional_params=additional_params,\n                )\n            )\n        except TimeoutError as e:\n            return f\"Timeout Exception occured in method : get_dataset_data_async. Details - {e!s}\"\n        except BrightDataDatasetToolException as e:\n            return (\n                f\"Exception occured in method : get_dataset_data_async. Details - {e!s}\"\n            )\n        except Exception as e:","sourceCodeStart":562,"sourceCodeEnd":598,"githubUrl":"https://github.com/crewAIInc/crewAI/blob/754d7323beb2fd042e33444a115ea2d5a47193f0/lib/crewai-tools/src/crewai_tools/tools/brightdata_tool/brightdata_dataset.py#L562-L598","documentation":"Raised by BrightDataDatasetTool._run when the BRIGHT_DATA_API_KEY environment variable is empty/missing. The tool reads the key only from the environment at call time (not from the constructor), so every dataset run requires it to be set beforehand.","triggerScenarios":"Running the tool without exporting BRIGHT_DATA_API_KEY; the variable set in a parent process but not in the container/notebook kernel executing the tool; key name typo (e.g. BRIGHTDATA_API_KEY).","commonSituations":".env not loaded, secrets configured per-environment but the code runs elsewhere, CI pipelines missing the env var.","solutions":["export BRIGHT_DATA_API_KEY=<token from Bright Data account settings>.","Call load_dotenv() before invoking the tool if the key lives in a .env file.","Inject via Docker (-e) or your platform's secret manager for deployments.","Prefer os.environ['BRIGHT_DATA_API_KEY'] lookups over shell-only exports for reproducibility."],"exampleFix":"# before\nresult = tool.run(url=url, dataset_type='amazon_product')  # ValueError\n\n# after\nimport os\nfrom dotenv import load_dotenv\nload_dotenv()\nif not os.getenv('BRIGHT_DATA_API_KEY'):\n    raise SystemExit('Missing BRIGHT_DATA_API_KEY')\nresult = tool.run(url=url, dataset_type='amazon_product')","handlingStrategy":"validation","validationCode":"import os\n\nif not os.getenv(\"BRIGHT_DATA_API_KEY\"):\n    raise SystemExit(\"BRIGHT_DATA_API_KEY must be set before running Bright Data dataset tools\")","typeGuard":null,"tryCatchPattern":"try:\n    result = tool.run(url=url, dataset_type=dt)\nexcept ValueError as e:\n    if \"BRIGHT_DATA_API_KEY\" in str(e):\n        load_dotenv()\n        result = tool.run(url=url, dataset_type=dt)\n    else:\n        raise","preventionTips":["Load .env at application startup, before any Bright Data tool call.","Assert required env vars in a boot-time config check.","Prefer platform secret injection (docker -e, k8s secrets) over shell exports in production."],"tags":["bright-data","environment-variables","api-key","configuration"],"backgroundTag":null,"analyzedSha":"754d7323beb2fd042e33444a115ea2d5a47193f0","analyzedAt":"2026-08-15T04:06:56.746Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}