microsoft/semantic-kernel · error · ServiceInitializationError

Error: missing Azure Cognitive Search client endpoint.

Error message

Error: missing Azure Cognitive Search client endpoint.

What it means

Raised in `get_search_index_async_client` (utils.py) when no search endpoint can be resolved: neither a `search_endpoint` argument nor the `AZURE_COGNITIVE_SEARCH_ENDPOINT` environment variable is provided (after `load_dotenv()`). The endpoint is mandatory to build a `SearchIndexClient`, so initialization fails with `ServiceInitializationError`.

Source

Thrown at python/semantic_kernel/connectors/memory_stores/azure_cognitive_search/utils.py:50

    Args:
        search_endpoint (str): Optional endpoint (default: {None}).
        admin_key (str): Optional API key (default: {None}).
        azure_credential (AzureKeyCredential): Optional Azure credentials (default: {None}).
        token_credential (TokenCredential): Optional Token credential (default: {None}).
    """
    ENV_VAR_ENDPOINT = "AZURE_COGNITIVE_SEARCH_ENDPOINT"
    ENV_VAR_API_KEY = "AZURE_COGNITIVE_SEARCH_ADMIN_KEY"

    # Load environment variables
    load_dotenv()

    # Service endpoint
    if search_endpoint:
        service_endpoint = search_endpoint
    elif os.getenv(ENV_VAR_ENDPOINT):
        service_endpoint = os.getenv(ENV_VAR_ENDPOINT)
    else:
        raise ServiceInitializationError("Error: missing Azure Cognitive Search client endpoint.")

    if service_endpoint is None:
        print(service_endpoint)
        raise ServiceInitializationError("Error: Azure Cognitive Search client not set.")

    # Credentials
    if admin_key:
        azure_credential = AzureKeyCredential(admin_key)
    elif azure_credential:
        azure_credential = azure_credential
    elif token_credential:
        token_credential = token_credential
    elif os.getenv(ENV_VAR_API_KEY):
        azure_credential = AzureKeyCredential(os.getenv(ENV_VAR_API_KEY))
    else:
        raise ServiceInitializationError("Error: missing Azure Cognitive Search client credentials.")

    if azure_credential is None and token_credential is None:

View on GitHub (pinned to c028a0c7dc)

Solutions

  1. Set `AZURE_COGNITIVE_SEARCH_ENDPOINT` in your environment or `.env` (e.g. `https://<service>.search.windows.net`).
  2. Pass `search_endpoint=` explicitly to the store constructor / `get_search_index_async_client`.
  3. Confirm `load_dotenv()` actually loads your `.env` (correct path and working directory).
  4. Verify the Azure Search service is provisioned and its endpoint copied correctly.

Example fix

// before
get_search_index_async_client(admin_key="...")  # no endpoint -> error

// after
get_search_index_async_client(
    search_endpoint="https://mysearch.search.windows.net",
    admin_key=os.environ["AZURE_COGNITIVE_SEARCH_ADMIN_KEY"],
)
Defensive patterns

Strategy: validation

Validate before calling

import os

def acs_endpoint_resolved(endpoint_arg) -> str | None:
    return endpoint_arg or os.getenv("AZURE_COGNITIVE_SEARCH_ENDPOINT")

# ep = acs_endpoint_resolved(search_endpoint)
# assert ep, "set AZURE_COGNITIVE_SEARCH_ENDPOINT or pass search_endpoint"

Type guard

def has_acs_endpoint(endpoint_arg) -> bool:
    import os
    return bool(endpoint_arg or os.getenv("AZURE_COGNITIVE_SEARCH_ENDPOINT"))

Try / catch

from semantic_kernel.exceptions import ServiceInitializationError
try:
    client = get_search_index_async_client(...)
except ServiceInitializationError as e:
    if "missing ... endpoint" in str(e):
        raise SystemExit("set AZURE_COGNITIVE_SEARCH_ENDPOINT") from e
    raise

Prevention

When it happens

Trigger: Calling `get_search_index_async_client(...)` (directly or via the memory store constructor) with `search_endpoint=None` while `AZURE_COGNITIVE_SEARCH_ENDPOINT` is unset in both the process environment and any loaded `.env` file.

Common situations: Forgotten env var; `.env` not on the path given by `env_file_path`; env var not exported in container/CI; typo in the variable name; deploying without provisioning an Azure Search service endpoint.

Related errors


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