{"record":{"id":"c6b764ae80be1299","repo":"stanford-oval/storm","slug":"you-must-supply-google-cse-id-or-set-the-google-cs","errorCode":null,"errorMessage":"You must supply google_cse_id or set the GOOGLE_CSE_ID environment variable","messagePattern":"You must supply google_cse_id or set the GOOGLE_CSE_ID environment variable","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"knowledge_storm/rm.py","lineNumber":1019,"sourceCode":"            k: Number of top results to retrieve.\n            is_valid_source: Optional function to filter valid sources.\n            min_char_count: Minimum character count for the article to be considered valid.\n            snippet_chunk_size: Maximum character count for each snippet.\n            webpage_helper_max_threads: Maximum number of threads to use for webpage helper.\n        \"\"\"\n        super().__init__(k=k)\n        try:\n            from googleapiclient.discovery import build\n        except ImportError as err:\n            raise ImportError(\n                \"GoogleSearch requires `pip install google-api-python-client`.\"\n            ) from err\n        if not google_search_api_key and not os.environ.get(\"GOOGLE_SEARCH_API_KEY\"):\n            raise RuntimeError(\n                \"You must supply google_search_api_key or set the GOOGLE_SEARCH_API_KEY environment variable\"\n            )\n        if not google_cse_id and not os.environ.get(\"GOOGLE_CSE_ID\"):\n            raise RuntimeError(\n                \"You must supply google_cse_id or set the GOOGLE_CSE_ID environment variable\"\n            )\n\n        self.google_search_api_key = (\n            google_search_api_key or os.environ[\"GOOGLE_SEARCH_API_KEY\"]\n        )\n        self.google_cse_id = google_cse_id or os.environ[\"GOOGLE_CSE_ID\"]\n\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        self.service = build(\n            \"customsearch\", \"v1\", developerKey=self.google_search_api_key\n        )\n        self.webpage_helper = WebPageHelper(\n            min_char_count=min_char_count,","sourceCodeStart":1001,"sourceCodeEnd":1037,"githubUrl":"https://github.com/stanford-oval/storm/blob/fb951af7744dab086e34962e9bc6fe878e145f83/knowledge_storm/rm.py#L1001-L1037","documentation":"Raised by GoogleSearchRM.__init__ (knowledge_storm/rm.py) when neither the google_cse_id constructor argument nor the GOOGLE_CSE_ID environment variable is set. The Google Custom Search Engine integration needs both an API key and a CSE (search engine) ID to issue queries, so the constructor fails fast before any search runs.","triggerScenarios":"Instantiating GoogleSearchRM (or GoogleSearch via rm) without passing google_cse_id and without GOOGLE_CSE_ID exported in the environment. Note the preceding check also requires google_search_api_key / GOOGLE_SEARCH_API_KEY, so that must already be satisfied to reach this error.","commonSituations":"Developer set GOOGLE_SEARCH_API_KEY but forgot the separate CSE ID; env vars defined in .env but not loaded into the process; CI/容器 environments where the variable isn't exported; confusing the API key with the CSE ID (cx parameter) from the Programmable Search control panel.","solutions":["Set the environment variable: export GOOGLE_CSE_ID=\"<your-cse-id>\" (the 'Search engine ID' from programmablesearchengine.google.com)","Or pass it explicitly: GoogleSearchSearchRM(graph=graph, google_search_api_key=..., google_cse_id=...)","Ensure the variable is actually loaded (e.g., load_dotenv() before construction) if it lives in a .env file"],"exampleFix":"# before\nrm = GoogleSearch(graph=graph, google_search_api_key=KEY)\n\n# after\nrm = GoogleSearch(graph=graph, google_search_api_key=KEY, google_cse_id=CSE_ID)\n# or: export GOOGLE_CSE_ID=...","handlingStrategy":"validation","validationCode":"import os\n\ndef has_google_cse_config(explicit_cse_id=None):\n    return bool(explicit_cse_id or os.environ.get(\"GOOGLE_CSE_ID\"))\n\nif not has_google_cse_config():\n    raise SystemExit(\"Set GOOGLE_CSE_ID before starting the pipeline.\")","typeGuard":null,"tryCatchPattern":"try:\n    rm = GoogleSearch(graph=graph, google_search_api_key=KEY)\nexcept RuntimeError as e:\n    if \"GOOGLE_CSE_ID\" in str(e):\n        # load config from a secrets manager / .env and retry once\n        load_dotenv()\n        rm = GoogleSearch(graph=graph, google_search_api_key=KEY)\n    else:\n        raise","preventionTips":["Centralize required env vars (GOOGLE_SEARCH_API_KEY, GOOGLE_CSE_ID) in one config module that validates them at startup","Load .env files before constructing retrievers","Fail fast at boot with a config check instead of mid-pipeline"],"tags":["google-search","env-var","configuration","storm"],"backgroundTag":"missing-env-var","analyzedSha":"fb951af7744dab086e34962e9bc6fe878e145f83","analyzedAt":"2026-08-28T11:56:54.780Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}