microsoft/semantic-kernel · error · ServiceInitializationError

Error: missing Azure AI Search client credentials.

Error message

Error: missing Azure AI Search client credentials.

What it means

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.

Source

Thrown at python/semantic_kernel/connectors/azure_ai_search.py:186

def _resolve_credential(
    azure_ai_search_settings: AzureAISearchSettings,
    azure_credential: AzureKeyCredential | None = None,
    token_credential: "AsyncTokenCredential | None" = None,
) -> "AzureKeyCredential | AsyncTokenCredential":
    """Resolve the credential to use for Azure AI Search.

    Args:
        azure_ai_search_settings: Azure AI Search settings.
        azure_credential: Optional Azure credentials (default: {None}).
        token_credential: Optional Token credential (default: {None}).
    """
    if azure_credential:
        return azure_credential
    if token_credential:
        return token_credential
    if azure_ai_search_settings.api_key:
        return AzureKeyCredential(azure_ai_search_settings.api_key.get_secret_value())
    raise ServiceInitializationError("Error: missing Azure AI Search client credentials.")


def _get_search_index_client(
    azure_ai_search_settings: AzureAISearchSettings,
    azure_credential: AzureKeyCredential | None = None,
    token_credential: "AsyncTokenCredential | None" = None,
) -> SearchIndexClient:
    """Return a client for Azure AI Search.

    Args:
        azure_ai_search_settings: Azure AI Search settings.
        azure_credential: Optional Azure credentials (default: {None}).
        token_credential: Optional Token credential (default: {None}).
    """
    credential = _resolve_credential(azure_ai_search_settings, azure_credential, token_credential)

    return SearchIndexClient(
        endpoint=str(azure_ai_search_settings.endpoint),

View on GitHub (pinned to c028a0c7dc)

Solutions

  1. Set the AZURE_AI_SEARCH_API_KEY environment variable (or put it in a .env file at the path passed as env_file_path).
  2. Pass api_key='...' directly into the AzureAISearchCollection/AzureAISearchStore constructor.
  3. For managed identity / Entra ID, pass token_credentials=DefaultAzureCredential() (or an AzureKeyCredential via azure_credentials=).
  4. 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.

Example fix

// before
store = AzureAISearchStore()  # no creds, no env

// after
from azure.identity import DefaultAzureCredential
store = AzureAISearchStore(
    search_endpoint="https://<svc>.search.windows.net",
    token_credentials=DefaultAzureCredential(),
)
Defensive patterns

Strategy: validation

Validate before calling

from azure.core.credentials import AzureKeyCredential
import os

def has_aisearch_credential(**kwargs) -> bool:
    return bool(
        kwargs.get("azure_credentials")
        or kwargs.get("token_credentials")
        or kwargs.get("api_key")
        or kwargs.get("search_credential")
        or os.getenv("AZURE_AI_SEARCH_API_KEY")
    )

if not has_aisearch_credential():
    raise RuntimeError("Supply api_key, azure_credentials, token_credentials, or set AZURE_AI_SEARCH_API_KEY")

Try / catch

from semantic_kernel.exceptions import ServiceInitializationError
try:
    store = AzureAISearchStore(search_endpoint=ep, api_key=key)
except ServiceInitializationError as e:
    if "missing Azure AI Search client credentials" in str(e):
        # configure credentials and retry init
        ...
    raise

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of microsoft/semantic-kernel@c028a0c7dc (2026-08-13). Data as JSON: /api/errors/1fe5a94a5ff7ad1e. Report an issue: GitHub.