{"record":{"id":"50605ef02c687406","repo":"stanford-oval/storm","slug":"you-must-supply-azure-ai-search-api-key-or-set-env","errorCode":null,"errorMessage":"You must supply azure_ai_search_api_key or set environment variable AZURE_AI_SEARCH_API_KEY","messagePattern":"You must supply azure_ai_search_api_key or set environment variable AZURE_AI_SEARCH_API_KEY","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"knowledge_storm/rm.py","lineNumber":1148,"sourceCode":"            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\n        try:\n            from azure.core.credentials import AzureKeyCredential\n            from azure.search.documents import SearchClient\n        except ImportError as err:\n            raise ImportError(\n                \"AzureAISearch requires `pip install azure-search-documents`.\"\n            ) from err\n\n        if not azure_ai_search_api_key and not os.environ.get(\n            \"AZURE_AI_SEARCH_API_KEY\"\n        ):\n            raise RuntimeError(\n                \"You must supply azure_ai_search_api_key or set environment variable AZURE_AI_SEARCH_API_KEY\"\n            )\n        elif azure_ai_search_api_key:\n            self.azure_ai_search_api_key = azure_ai_search_api_key\n        else:\n            self.azure_ai_search_api_key = os.environ[\"AZURE_AI_SEARCH_API_KEY\"]\n\n        if not azure_ai_search_url and not os.environ.get(\"AZURE_AI_SEARCH_URL\"):\n            raise RuntimeError(\n                \"You must supply azure_ai_search_url or set environment variable AZURE_AI_SEARCH_URL\"\n            )\n        elif azure_ai_search_url:\n            self.azure_ai_search_url = azure_ai_search_url\n        else:\n            self.azure_ai_search_url = os.environ[\"AZURE_AI_SEARCH_URL\"]\n\n        if not azure_ai_search_index_name and not os.environ.get(\n            \"AZURE_AI_SEARCH_INDEX_NAME\"","sourceCodeStart":1130,"sourceCodeEnd":1166,"githubUrl":"https://github.com/stanford-oval/storm/blob/fb951af7744dab086e34962e9bc6fe878e145f83/knowledge_storm/rm.py#L1130-L1166","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["export AZURE_AI_SEARCH_API_KEY=\"<your-admin-or-query-key>\"","Or pass it explicitly: AzureAISearchRM(azure_ai_search_api_key=KEY, azure_ai_search_url=..., azure_ai_search_index_name=...)","Confirm the variable is loaded into the actual process (load_dotenv() / container env) before constructing the retriever"],"exampleFix":"# before\nrm = AzureAISearchRM(azure_ai_search_url=URL, azure_ai_search_index_name=IDX)\n\n# after\nrm = AzureAISearchRM(azure_ai_search_api_key=KEY, azure_ai_search_url=URL, azure_ai_search_index_name=IDX)","handlingStrategy":"validation","validationCode":"import os\n\ndef has_azure_search_key(explicit=None):\n    return bool(explicit or os.environ.get(\"AZURE_AI_SEARCH_API_KEY\"))\n\nassert has_azure_search_key(), \"Missing AZURE_AI_SEARCH_API_KEY\"","typeGuard":null,"tryCatchPattern":"try:\n    rm = AzureAISearchRM(azure_ai_search_url=U, azure_ai_search_index_name=I)\nexcept RuntimeError as e:\n    if \"AZURE_AI_SEARCH_API_KEY\" in str(e):\n        load_dotenv()\n        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)\n    else:\n        raise","preventionTips":["Validate all three Azure settings (key, url, index) in a startup config check","Inject secrets via env vars in deployment rather than hardcoding","Use a single env-loading step (load_dotenv) at process start"],"tags":["azure","env-var","configuration","api-key"],"backgroundTag":"missing-env-var","analyzedSha":"fb951af7744dab086e34962e9bc6fe878e145f83","analyzedAt":"2026-08-28T11:56:54.780Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}