{"record":{"id":"e424f7e3d4101b10","repo":"microsoft/semantic-kernel","slug":"please-provide-a-credential-to-retrieve-the-authen","errorCode":null,"errorMessage":"Please provide a credential to retrieve the authentication token.","messagePattern":"Please provide a credential to retrieve the authentication token\\.","errorType":"exception","errorClass":"ServiceInitializationError","httpStatus":null,"severity":"error","filePath":"python/semantic_kernel/connectors/ai/open_ai/settings/azure_open_ai_settings.py","lineNumber":134,"sourceCode":"        The token endpoint may be specified as an environment variable, via the .env\n        file or as an argument. If the token endpoint is not provided, the default is None.\n        The `token_endpoint` argument takes precedence over the `token_endpoint` attribute.\n\n        Args:\n            credential: The credential to use for authentication.\n            token_endpoint: The token endpoint to use. Defaults to `https://cognitiveservices.azure.com/.default`.\n\n        Returns:\n            The Azure token or None if the token could not be retrieved.\n\n        Raises:\n            ServiceInitializationError: If the token endpoint is not provided.\n        \"\"\"\n        endpoint_to_use = token_endpoint or self.token_endpoint\n        if endpoint_to_use is None:\n            raise ServiceInitializationError(\"Please provide a token endpoint to retrieve the authentication token.\")\n        if credential is None:\n            raise ServiceInitializationError(\"Please provide a credential to retrieve the authentication token.\")\n        return get_entra_auth_token(credential, endpoint_to_use)\n","sourceCodeStart":116,"sourceCodeEnd":136,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/python/semantic_kernel/connectors/ai/open_ai/settings/azure_open_ai_settings.py#L116-L136","documentation":"Raised by AzureOpenAISettings.get_azure_openai_auth_token when credential is None. The method requires an azure.core.credentials TokenCredential to call get_entra_auth_token; if none is passed it throws ServiceInitializationError before attempting the token request.","triggerScenarios":"Calling settings.get_azure_openai_auth_token() with no credential argument and no default credential available (the parameter has no fallback — it must be supplied by the caller).","commonSituations":"The caller forgot to pass a credential; DefaultAzureCredential construction failed silently upstream and passed None; running in an environment without a managed identity and the credential object was never built.","solutions":["Pass a TokenCredential, e.g. from azure.identity: from azure.identity import DefaultAzureCredential; settings.get_azure_openai_auth_token(credential=DefaultAzureCredential())","Ensure your runtime has a valid identity (managed identity, az login, or environment vars for AzureIdentity)","Construct and validate the credential object once at startup and reuse it"],"exampleFix":"# before\nsettings.get_azure_openai_auth_token(token_endpoint=\"https://cognitiveservices.azure.com/.default\")\n\n# after\nfrom azure.identity import DefaultAzureCredential\nsettings.get_azure_openai_auth_token(credential=DefaultAzureCredential())","handlingStrategy":"validation","validationCode":"if credential is None:\n    raise ValueError(\"A TokenCredential is required for Azure Entra auth\")\ntoken = settings.get_azure_openai_auth_token(credential=credential)","typeGuard":"from azure.core.credentials import TokenCredential\n\n\ndef is_token_credential(c: object | None) -> bool:\n    return isinstance(c, TokenCredential)","tryCatchPattern":"from semantic_kernel.exceptions.service_exceptions import ServiceInitializationError\n\ntry:\n    token = settings.get_azure_openai_auth_token(credential=cred)\nexcept ServiceInitializationError as e:\n    if \"credential\" in str(e):\n        raise SystemExit(\"Pass an azure.core.credentials TokenCredential\") from e\n    raise","preventionTips":["Construct the credential once at startup and validate it resolves a token","Use DefaultAzureCredential for local dev and managed identity in prod","Never call get_azure_openai_auth_token without a credential argument"],"tags":["azure","azure-openai","authentication","configuration","python"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}