{"record":{"id":"04844cae2d038eea","repo":"microsoft/semantic-kernel","slug":"error-azure-cognitive-search-credentials-not-set","errorCode":null,"errorMessage":"Error: Azure Cognitive Search credentials not set.","messagePattern":"Error: Azure Cognitive Search credentials not set\\.","errorType":"validation","errorClass":"ServiceInitializationError","httpStatus":null,"severity":"error","filePath":"python/semantic_kernel/connectors/memory_stores/azure_cognitive_search/utils.py","lineNumber":69,"sourceCode":"\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\n    Args:\n        vector_size (int): The size of the vectors being stored in collection/index.\n        vector_search_profile_name (str): The name of the vector search profile.","sourceCodeStart":51,"sourceCodeEnd":87,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/python/semantic_kernel/connectors/memory_stores/azure_cognitive_search/utils.py#L51-L87","documentation":"Defensive guard in `get_search_index_async_client`: after the credential-resolution block, it asserts that at least one of `azure_credential`/`token_credential` is non-None, raising `ServiceInitializationError` otherwise. Under the current if/elif/else flow this is largely unreachable because the `else` branch (error 1373) already raises when nothing is supplied; it protects against a regression where credentials end up None unexpectedly.","triggerScenarios":"Reachable only if the credential assignment logic is altered so both variables remain None while skipping the `else` raise, or via unusual monkeypatching. Under normal control flow it does not fire because error 1373 fires first.","commonSituations":"Test harness patching credential objects to None; a refactor breaking the credential branches; passing a falsy credential object that the branches skip.","solutions":["Provide a valid `admin_key`, `azure_credential`, or `token_credential` (or `AZURE_COGNITIVE_SEARCH_ADMIN_KEY`) so resolution succeeds at the earlier branches.","If encountered unexpectedly, audit any monkeypatching of the credential arguments or the factory.","Report as a bug if reached during normal configuration."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"# Defensive/unreachable under normal flow; ensure a credential object is truthy.\nassert azure_credential or token_credential, \"credential objects unexpectedly None\"","typeGuard":"def has_resolved_credential(azure_credential, token_credential) -> bool:\n    return bool(azure_credential) or bool(token_credential)","tryCatchPattern":"from semantic_kernel.exceptions import ServiceInitializationError\ntry:\n    client = get_search_index_async_client(...)\nexcept ServiceInitializationError as e:\n    if \"credentials not set\" in str(e):\n        raise SystemExit(\"credential resolution regression; supply valid credential\") from e\n    raise","preventionTips":["Pass a valid credential object so the normal path is taken.","Audit any monkeypatching of credential arguments.","Treat encountering this branch as a regression/bug."],"tags":["azure-cognitive-search","credentials","defensive-guard","semantic-kernel"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}