stanford-oval/storm · critical · RuntimeError
You must supply brave_search_api_key or set environment vari
Error message
You must supply brave_search_api_key or set environment variable BRAVE_API_KEY
What it means
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.
Source
Thrown at knowledge_storm/rm.py:576
knowledge_graph.get("description")
if knowledge_graph is not None
else ""
),
}
)
except:
continue
return collected_results
class BraveRM(dspy.Retrieve):
def __init__(
self, brave_search_api_key=None, k=3, is_valid_source: Callable = None
):
super().__init__(k=k)
if not brave_search_api_key and not os.environ.get("BRAVE_API_KEY"):
raise RuntimeError(
"You must supply brave_search_api_key or set environment variable BRAVE_API_KEY"
)
elif brave_search_api_key:
self.brave_search_api_key = brave_search_api_key
else:
self.brave_search_api_key = os.environ["BRAVE_API_KEY"]
self.usage = 0
# If not None, is_valid_source shall be a function that takes a URL and returns a boolean.
if is_valid_source:
self.is_valid_source = is_valid_source
else:
self.is_valid_source = lambda x: True
def get_usage_and_reset(self):
usage = self.usage
self.usage = 0
View on GitHub (pinned to fb951af774)
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
Example fix
# before rm = BraveRM(k=3) # after rm = BraveRM(brave_search_api_key='your_key', k=3) # or: os.environ['BRAVE_API_KEY'] = 'your_key' before construction
Defensive patterns
Strategy: validation
Validate before calling
import os
assert 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" Try / catch
try:
rm = BraveRM(k=3)
except RuntimeError as e:
if 'BRAVE_API_KEY' in str(e):
raise SystemExit('Configure BRAVE_API_KEY before running')
raise Prevention
- 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
When it happens
Trigger: Instantiating BraveRM() with no brave_search_api_key argument while BRAVE_API_KEY is unset or empty in the environment.
Common situations: 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).
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 searxng_api_url
- You must supply azure_ai_search_api_key or set environment v
- No valid OpenAI API provider is provided. Cannot use default
- Please provide an embedding model.
- Qdrant client is not initialized.
AI-assisted analysis of stanford-oval/storm@fb951af774 (2026-08-28).
Data as JSON: /api/errors/04a4863dcc244a0f.
Report an issue: GitHub.