{"record":{"id":"04a4863dcc244a0f","repo":"stanford-oval/storm","slug":"you-must-supply-brave-search-api-key-or-set-enviro","errorCode":null,"errorMessage":"You must supply brave_search_api_key or set environment variable BRAVE_API_KEY","messagePattern":"You must supply brave_search_api_key or set environment variable BRAVE_API_KEY","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"critical","filePath":"knowledge_storm/rm.py","lineNumber":576,"sourceCode":"                                knowledge_graph.get(\"description\")\n                                if knowledge_graph is not None\n                                else \"\"\n                            ),\n                        }\n                    )\n            except:\n                continue\n\n        return collected_results\n\n\nclass BraveRM(dspy.Retrieve):\n    def __init__(\n        self, brave_search_api_key=None, k=3, is_valid_source: Callable = None\n    ):\n        super().__init__(k=k)\n        if not brave_search_api_key and not os.environ.get(\"BRAVE_API_KEY\"):\n            raise RuntimeError(\n                \"You must supply brave_search_api_key or set environment variable BRAVE_API_KEY\"\n            )\n        elif brave_search_api_key:\n            self.brave_search_api_key = brave_search_api_key\n        else:\n            self.brave_search_api_key = os.environ[\"BRAVE_API_KEY\"]\n        self.usage = 0\n\n        # If not None, is_valid_source shall be a function that takes a URL and returns a boolean.\n        if is_valid_source:\n            self.is_valid_source = is_valid_source\n        else:\n            self.is_valid_source = lambda x: True\n\n    def get_usage_and_reset(self):\n        usage = self.usage\n        self.usage = 0\n","sourceCodeStart":558,"sourceCodeEnd":594,"githubUrl":"https://github.com/stanford-oval/storm/blob/fb951af7744dab086e34962e9bc6fe878e145f83/knowledge_storm/rm.py#L558-L594","documentation":"BraveRM.__init__ raises this when no Brave Search API key is available. The retriever requires a key either passed explicitly or present in the BRAVE_API_KEY environment variable; without one it cannot authenticate to Brave's Search API.","triggerScenarios":"Instantiating BraveRM() with no brave_search_api_key argument while BRAVE_API_KEY is unset or empty in the environment.","commonSituations":"New developer forgets to copy .env to the deployment environment, CI/CD pipeline lacks the secret, docker container built without the env var, or a typo in the variable name (e.g. BRAVE_SEARCH_API_KEY).","solutions":["Export BRAVE_API_KEY in your shell or .env: export BRAVE_API_KEY=your_key","Pass the key explicitly: BraveRM(brave_search_api_key='your_key')","Verify with: python -c \"import os; print(bool(os.environ.get('BRAVE_API_KEY')))\"","If using dotenv, ensure load_dotenv() runs before constructing BraveRM"],"exampleFix":"# before\nrm = BraveRM(k=3)\n\n# after\nrm = BraveRM(brave_search_api_key='your_key', k=3)\n# or: os.environ['BRAVE_API_KEY'] = 'your_key' before construction","handlingStrategy":"validation","validationCode":"import os\nassert os.environ.get(\"BRAVE_API_KEY\") or BRAVE_KEY_FROM_CONFIG, \"BRAVE_API_KEY not set; get one at https://api-dashboard.search.brave.com\"","typeGuard":null,"tryCatchPattern":"try:\n    rm = BraveRM(k=3)\nexcept RuntimeError as e:\n    if 'BRAVE_API_KEY' in str(e):\n        raise SystemExit('Configure BRAVE_API_KEY before running')\n    raise","preventionTips":["Centralize env-var loading (load_dotenv()) at app entrypoint","Fail fast at startup with a config checklist for all required keys","Use a secrets manager in CI/CD instead of manual exports"],"tags":["configuration","api-key","missing-env-var","brave-search","initialization"],"backgroundTag":"missing-env-var","analyzedSha":"fb951af7744dab086e34962e9bc6fe878e145f83","analyzedAt":"2026-08-28T11:56:54.780Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}