{"record":{"id":"1fe5a94a5ff7ad1e","repo":"microsoft/semantic-kernel","slug":"error-missing-azure-ai-search-client-credentials","errorCode":null,"errorMessage":"Error: missing Azure AI Search client credentials.","messagePattern":"Error: missing Azure AI Search client credentials\\.","errorType":"exception","errorClass":"ServiceInitializationError","httpStatus":null,"severity":"error","filePath":"python/semantic_kernel/connectors/azure_ai_search.py","lineNumber":186,"sourceCode":"def _resolve_credential(\n    azure_ai_search_settings: AzureAISearchSettings,\n    azure_credential: AzureKeyCredential | None = None,\n    token_credential: \"AsyncTokenCredential | None\" = None,\n) -> \"AzureKeyCredential | AsyncTokenCredential\":\n    \"\"\"Resolve the credential to use for Azure AI Search.\n\n    Args:\n        azure_ai_search_settings: Azure AI Search settings.\n        azure_credential: Optional Azure credentials (default: {None}).\n        token_credential: Optional Token credential (default: {None}).\n    \"\"\"\n    if azure_credential:\n        return azure_credential\n    if token_credential:\n        return token_credential\n    if azure_ai_search_settings.api_key:\n        return AzureKeyCredential(azure_ai_search_settings.api_key.get_secret_value())\n    raise ServiceInitializationError(\"Error: missing Azure AI Search client credentials.\")\n\n\ndef _get_search_index_client(\n    azure_ai_search_settings: AzureAISearchSettings,\n    azure_credential: AzureKeyCredential | None = None,\n    token_credential: \"AsyncTokenCredential | None\" = None,\n) -> SearchIndexClient:\n    \"\"\"Return a client for Azure AI Search.\n\n    Args:\n        azure_ai_search_settings: Azure AI Search settings.\n        azure_credential: Optional Azure credentials (default: {None}).\n        token_credential: Optional Token credential (default: {None}).\n    \"\"\"\n    credential = _resolve_credential(azure_ai_search_settings, azure_credential, token_credential)\n\n    return SearchIndexClient(\n        endpoint=str(azure_ai_search_settings.endpoint),","sourceCodeStart":168,"sourceCodeEnd":204,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/python/semantic_kernel/connectors/azure_ai_search.py#L168-L204","documentation":"Raised by _resolve_credential during client creation when none of the three credential sources is available: an explicit azure_credential (AzureKeyCredential), a token_credential (AsyncTokenCredential), or an api_key in AzureAISearchSettings (env var AZURE_AI_SEARCH_API_KEY). The connector cannot construct an authenticated SearchClient/SearchIndexClient without at least one. It is a ServiceInitializationError (not a vector-store exception) because it is a setup/configuration defect.","triggerScenarios":"Constructing AzureAISearchCollection or AzureAISearchStore (or calling _get_search_index_client / _get_search_client) without passing search_credential, azure_credentials, token_credentials, or api_key, and with AZURE_AI_SEARCH_API_KEY unset in the environment/.env file. Also fires when only an endpoint is configured but no credential accompanies it.","commonSituations":"Running locally without a .env file loaded; deploying to a host where the AZURE_AI_SEARCH_API_KEY secret was never injected; switching from key auth to managed identity but forgetting to pass token_credentials=DefaultAzureCredential(); copying sample code that omitted the credential argument.","solutions":["Set the AZURE_AI_SEARCH_API_KEY environment variable (or put it in a .env file at the path passed as env_file_path).","Pass api_key='...' directly into the AzureAISearchCollection/AzureAISearchStore constructor.","For managed identity / Entra ID, pass token_credentials=DefaultAzureCredential() (or an AzureKeyCredential via azure_credentials=).","Verify the env file is actually loaded — confirm AZURE_AI_SEARCH_ENDPOINT resolves too, since settings construction would otherwise fail first on the required HttpsUrl field."],"exampleFix":"// before\nstore = AzureAISearchStore()  # no creds, no env\n\n// after\nfrom azure.identity import DefaultAzureCredential\nstore = AzureAISearchStore(\n    search_endpoint=\"https://<svc>.search.windows.net\",\n    token_credentials=DefaultAzureCredential(),\n)","handlingStrategy":"validation","validationCode":"from azure.core.credentials import AzureKeyCredential\nimport os\n\ndef has_aisearch_credential(**kwargs) -> bool:\n    return bool(\n        kwargs.get(\"azure_credentials\")\n        or kwargs.get(\"token_credentials\")\n        or kwargs.get(\"api_key\")\n        or kwargs.get(\"search_credential\")\n        or os.getenv(\"AZURE_AI_SEARCH_API_KEY\")\n    )\n\nif not has_aisearch_credential():\n    raise RuntimeError(\"Supply api_key, azure_credentials, token_credentials, or set AZURE_AI_SEARCH_API_KEY\")","typeGuard":null,"tryCatchPattern":"from semantic_kernel.exceptions import ServiceInitializationError\ntry:\n    store = AzureAISearchStore(search_endpoint=ep, api_key=key)\nexcept ServiceInitializationError as e:\n    if \"missing Azure AI Search client credentials\" in str(e):\n        # configure credentials and retry init\n        ...\n    raise","preventionTips":["Centralize Azure AI Search settings in a .env file and load it explicitly via env_file_path.","For production, prefer token_credentials=DefaultAzureCredential() over raw API keys.","Add a startup smoke test that constructs the store and fails fast on missing credentials."],"tags":["authentication","configuration","azure-ai-search","startup"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}