stanford-oval/storm · error · RuntimeError

You must supply azure_ai_search_api_key or set environment v

Error message

You must supply azure_ai_search_api_key or set environment variable AZURE_AI_SEARCH_API_KEY

What it means

Raised by AzureAISearchRM.__init__ when the Azure AI Search API key is neither passed as the azure_ai_search_api_key argument nor present in the AZURE_AI_SEARCH_API_KEY environment variable. Like the other Azure settings, it is resolved lazily at construction time and the constructor fails fast with this RuntimeError.

Source

Thrown at knowledge_storm/rm.py:1148

            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 azure.core.credentials import AzureKeyCredential
            from azure.search.documents import SearchClient
        except ImportError as err:
            raise ImportError(
                "AzureAISearch requires `pip install azure-search-documents`."
            ) from err

        if not azure_ai_search_api_key and not os.environ.get(
            "AZURE_AI_SEARCH_API_KEY"
        ):
            raise RuntimeError(
                "You must supply azure_ai_search_api_key or set environment variable AZURE_AI_SEARCH_API_KEY"
            )
        elif azure_ai_search_api_key:
            self.azure_ai_search_api_key = azure_ai_search_api_key
        else:
            self.azure_ai_search_api_key = os.environ["AZURE_AI_SEARCH_API_KEY"]

        if not azure_ai_search_url and not os.environ.get("AZURE_AI_SEARCH_URL"):
            raise RuntimeError(
                "You must supply azure_ai_search_url or set environment variable AZURE_AI_SEARCH_URL"
            )
        elif azure_ai_search_url:
            self.azure_ai_search_url = azure_ai_search_url
        else:
            self.azure_ai_search_url = os.environ["AZURE_AI_SEARCH_URL"]

        if not azure_ai_search_index_name and not os.environ.get(
            "AZURE_AI_SEARCH_INDEX_NAME"

View on GitHub (pinned to fb951af774)

Solutions

  1. export AZURE_AI_SEARCH_API_KEY="<your-admin-or-query-key>"
  2. Or pass it explicitly: AzureAISearchRM(azure_ai_search_api_key=KEY, azure_ai_search_url=..., azure_ai_search_index_name=...)
  3. Confirm the variable is loaded into the actual process (load_dotenv() / container env) before constructing the retriever

Example fix

# before
rm = AzureAISearchRM(azure_ai_search_url=URL, azure_ai_search_index_name=IDX)

# after
rm = AzureAISearchRM(azure_ai_search_api_key=KEY, azure_ai_search_url=URL, azure_ai_search_index_name=IDX)
Defensive patterns

Strategy: validation

Validate before calling

import os

def has_azure_search_key(explicit=None):
    return bool(explicit or os.environ.get("AZURE_AI_SEARCH_API_KEY"))

assert has_azure_search_key(), "Missing AZURE_AI_SEARCH_API_KEY"

Try / catch

try:
    rm = AzureAISearchRM(azure_ai_search_url=U, azure_ai_search_index_name=I)
except RuntimeError as e:
    if "AZURE_AI_SEARCH_API_KEY" in str(e):
        load_dotenv()
        rm = AzureAISearchRM(azure_ai_search_api_key=os.environ["AZURE_AI_SEARCH_API_KEY"], azure_ai_search_url=U, azure_ai_search_index_name=I)
    else:
        raise

Prevention

When it happens

Trigger: Constructing AzureAISearchRM with no azure_ai_search_api_key argument while AZURE_AI_SEARCH_API_KEY is unset or empty. This check runs after the azure-search-documents import succeeds.

Common situations: Other Azure env vars (URL, index name) were set but the key was missed; the key is stored in a .env file that wasn't loaded; the admin/query key was copied incorrectly or is an empty string, which is falsy and triggers the same path.

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


AI-assisted analysis of stanford-oval/storm@fb951af774 (2026-08-28). Data as JSON: /api/errors/50605ef02c687406. Report an issue: GitHub.