stanford-oval/storm · error · RuntimeError
You must supply google_cse_id or set the GOOGLE_CSE_ID envir
Error message
You must supply google_cse_id or set the GOOGLE_CSE_ID environment variable
What it means
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.
Source
Thrown at knowledge_storm/rm.py:1019
k: Number of top results to retrieve.
is_valid_source: Optional function to filter valid sources.
min_char_count: Minimum character count for the article to be considered valid.
snippet_chunk_size: Maximum character count for each snippet.
webpage_helper_max_threads: Maximum number of threads to use for webpage helper.
"""
super().__init__(k=k)
try:
from googleapiclient.discovery import build
except ImportError as err:
raise ImportError(
"GoogleSearch requires `pip install google-api-python-client`."
) from err
if not google_search_api_key and not os.environ.get("GOOGLE_SEARCH_API_KEY"):
raise RuntimeError(
"You must supply google_search_api_key or set the GOOGLE_SEARCH_API_KEY environment variable"
)
if not google_cse_id and not os.environ.get("GOOGLE_CSE_ID"):
raise RuntimeError(
"You must supply google_cse_id or set the GOOGLE_CSE_ID environment variable"
)
self.google_search_api_key = (
google_search_api_key or os.environ["GOOGLE_SEARCH_API_KEY"]
)
self.google_cse_id = google_cse_id or os.environ["GOOGLE_CSE_ID"]
if is_valid_source:
self.is_valid_source = is_valid_source
else:
self.is_valid_source = lambda x: True
self.service = build(
"customsearch", "v1", developerKey=self.google_search_api_key
)
self.webpage_helper = WebPageHelper(
min_char_count=min_char_count,View on GitHub (pinned to fb951af774)
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
Example fix
# before rm = GoogleSearch(graph=graph, google_search_api_key=KEY) # after rm = GoogleSearch(graph=graph, google_search_api_key=KEY, google_cse_id=CSE_ID) # or: export GOOGLE_CSE_ID=...
Defensive patterns
Strategy: validation
Validate before calling
import os
def has_google_cse_config(explicit_cse_id=None):
return bool(explicit_cse_id or os.environ.get("GOOGLE_CSE_ID"))
if not has_google_cse_config():
raise SystemExit("Set GOOGLE_CSE_ID before starting the pipeline.") Try / catch
try:
rm = GoogleSearch(graph=graph, google_search_api_key=KEY)
except RuntimeError as e:
if "GOOGLE_CSE_ID" in str(e):
# load config from a secrets manager / .env and retry once
load_dotenv()
rm = GoogleSearch(graph=graph, google_search_api_key=KEY)
else:
raise Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: "environment variable is not set" and "Missing keys in environment" errors: what missing required env var messages mean and how to fix them — this error's family across 28 libraries.
Related errors
- You must supply azure_ai_search_api_key or set environment v
- You must supply azure_ai_search_url or set environment varia
- You must supply azure_ai_search_index_name or set environmen
- Please provide an embedding model.
- Please provide a url for the Qdrant server.
AI-assisted analysis of stanford-oval/storm@fb951af774 (2026-08-28).
Data as JSON: /api/errors/c6b764ae80be1299.
Report an issue: GitHub.