{"record":{"id":"7d83ff58077f6354","repo":"microsoft/semantic-kernel","slug":"error-missing-azure-cognitive-search-client-crede","errorCode":null,"errorMessage":"Error: missing Azure Cognitive Search client credentials.","messagePattern":"Error: missing Azure Cognitive Search client credentials\\.","errorType":"validation","errorClass":"ServiceInitializationError","httpStatus":null,"severity":"error","filePath":"python/semantic_kernel/connectors/memory_stores/azure_cognitive_search/utils.py","lineNumber":66,"sourceCode":"        service_endpoint = os.getenv(ENV_VAR_ENDPOINT)\n    else:\n        raise ServiceInitializationError(\"Error: missing Azure Cognitive Search client endpoint.\")\n\n    if service_endpoint is None:\n        print(service_endpoint)\n        raise ServiceInitializationError(\"Error: Azure Cognitive Search client not set.\")\n\n    # Credentials\n    if admin_key:\n        azure_credential = AzureKeyCredential(admin_key)\n    elif azure_credential:\n        azure_credential = azure_credential\n    elif token_credential:\n        token_credential = token_credential\n    elif os.getenv(ENV_VAR_API_KEY):\n        azure_credential = AzureKeyCredential(os.getenv(ENV_VAR_API_KEY))\n    else:\n        raise ServiceInitializationError(\"Error: missing Azure Cognitive Search client credentials.\")\n\n    if azure_credential is None and token_credential is None:\n        raise ServiceInitializationError(\"Error: Azure Cognitive Search credentials not set.\")\n\n    sk_headers = {USER_AGENT: \"Semantic-Kernel\"}\n\n    if azure_credential:\n        return SearchIndexClient(endpoint=service_endpoint, credential=azure_credential, headers=sk_headers)\n\n    if token_credential:\n        return SearchIndexClient(endpoint=service_endpoint, credential=token_credential, headers=sk_headers)\n\n    raise ValueError(\"Error: unable to create Azure Cognitive Search client.\")\n\n\ndef get_index_schema(vector_size: int, vector_search_profile_name: str) -> list:\n    \"\"\"Return the schema of search indexes.\n","sourceCodeStart":48,"sourceCodeEnd":84,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/python/semantic_kernel/connectors/memory_stores/azure_cognitive_search/utils.py#L48-L84","documentation":"Raised in `get_search_index_async_client` when no credentials of any kind can be resolved: `admin_key` is not provided, neither `azure_credential` nor `token_credential` objects are passed, and the `AZURE_COGNITIVE_SEARCH_ADMIN_KEY` env var is unset. Without credentials the `SearchIndexClient` cannot be constructed, so initialization fails with `ServiceInitializationError`.","triggerScenarios":"Calling the client factory / store constructor without `admin_key`, `azure_credential`, or `token_credential`, while `AZURE_COGNITIVE_SEARCH_ADMIN_KEY` is absent from the environment and `.env`.","commonSituations":"Forgetting to set the admin key env var; intending to use managed identity/`DefaultAzureCredential` but not passing a `token_credential`; `.env` not loaded; CI secret not injected; using a read-only query key where an admin key is required.","solutions":["Set `AZURE_COGNITIVE_SEARCH_ADMIN_KEY` (or pass `admin_key=`) for key-based auth.","For AAD/managed identity, pass a `token_credential` such as `DefaultAzureCredential()`.","Ensure `load_dotenv()` sees your `.env` with the key, and that CI injects the secret.","Use an admin (query-key-for-admin) key, not a query-only key, where admin operations are required."],"exampleFix":"// before\nget_search_index_async_client(search_endpoint=\"https://...search.windows.net\")  # no creds\n\n// after\n# option A: key auth\nget_search_index_async_client(\n    search_endpoint=\"https://...search.windows.net\",\n    admin_key=os.environ[\"AZURE_COGNITIVE_SEARCH_ADMIN_KEY\"],\n)\n# option B: token credential\nfrom azure.identity import DefaultAzureCredential\nget_search_index_async_client(\n    search_endpoint=\"https://...search.windows.net\",\n    token_credential=DefaultAzureCredential(),\n)","handlingStrategy":"validation","validationCode":"import os\n\ndef acs_creds_resolved(admin_key, azure_credential, token_credential) -> bool:\n    return bool(admin_key or azure_credential or token_credential\n               or os.getenv(\"AZURE_COGNITIVE_SEARCH_ADMIN_KEY\"))\n\n# assert acs_creds_resolved(...) before building the client","typeGuard":"def has_acs_credentials(admin_key, azure_credential, token_credential) -> bool:\n    import os\n    return bool(admin_key or azure_credential or token_credential\n               or os.getenv(\"AZURE_COGNITIVE_SEARCH_ADMIN_KEY\"))","tryCatchPattern":"from semantic_kernel.exceptions import ServiceInitializationError\ntry:\n    client = get_search_index_async_client(...)\nexcept ServiceInitializationError as e:\n    if \"credentials\" in str(e):\n        raise SystemExit(\"provide admin_key or token_credential or AZURE_COGNITIVE_SEARCH_ADMIN_KEY\") from e\n    raise","preventionTips":["Provide an admin key (env or arg) or a `token_credential` such as `DefaultAzureCredential`.","Validate credential presence at startup.","Use an admin-capable key for index management operations.","Keep secrets in env/CI secret variables."],"tags":["azure-cognitive-search","credentials","auth","config","service-initialization","semantic-kernel"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}