{"id":4988,"date":"2025-08-26T22:16:27","date_gmt":"2025-08-27T05:16:27","guid":{"rendered":"https:\/\/devblogs.microsoft.com\/semantic-kernel\/?p=4988"},"modified":"2025-08-26T22:20:30","modified_gmt":"2025-08-27T05:20:30","slug":"azure-authentication-changes-in-semantic-kernel-python","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/agent-framework\/azure-authentication-changes-in-semantic-kernel-python\/","title":{"rendered":"Azure Authentication Changes in Semantic Kernel Python"},"content":{"rendered":"<p>In previous versions of the Semantic Kernel Python, the default fallback authentication mechanism for Azure services like <code>AzureChatCompletion<\/code> was <code>DefaultAzureCredential<\/code> from the Azure Identity library. This provided a convenient way to authenticate without explicitly passing credentials, especially during development. However, with the latest package version <code>1.36.0<\/code>, this fallback is being removed to encourage more secure and explicit authentication practices. If your code relied on this default behavior, you may encounter errors after updating, and you&#8217;ll need to make minor code adjustments to continue using credential-based authentication.<\/p>\n<p>This post explains the reasoning behind this change, the potential issues you might face, and how to update your code accordingly. For more details on Azure authentication options, check out the <a href=\"https:\/\/learn.microsoft.com\/en-us\/python\/api\/overview\/azure\/identity-readme?view=azure-python\">Azure Identity library documentation<\/a>.<\/p>\n<h2><strong>Why This Change is Required<\/strong><\/h2>\n<p><code>DefaultAzureCredential<\/code> is designed primarily for local development environments, where it simplifies authentication by attempting a chain of common developer credentials (such as Azure CLI, Azure PowerShell, or Visual Studio Code sign-ins) until one succeeds. While this is helpful for quick prototyping, it introduces several risks and limitations in production:<\/p>\n<ol>\n<li><strong>Unpredictable Behavior:<\/strong> It tries multiple authentication methods in sequence, which can lead to delays, unexpected failures, or reliance on credentials that aren&#8217;t consistently available across environments.<\/li>\n<li><strong>Interactive Authentication Fallback:<\/strong> By default, it can prompt for interactive browser-based login, which is unsuitable for automated, headless production applications running on servers or in cloud environments.<\/li>\n<li><strong>Security and Best Practices:<\/strong> Production scenarios benefit from explicit, dedicated credentials like managed identities or service principals, which offer better control, auditing, and security. Using a broad fallback like <code>DefaultAzureCredential<\/code> can mask configuration issues and doesn&#8217;t align with principles of least privilege.<\/li>\n<\/ol>\n<p>For these reasons, we recommend using specific credential types tailored to your deployment environment in production to ensure reliability and security.<\/p>\n<h2><strong>Changes in the Latest Version and Potential Errors<\/strong><\/h2>\n<p>Starting with the new SDK version, the implicit use of <code>DefaultAzureCredential<\/code> as a fallback has been removed. This means that if your code doesn&#8217;t explicitly provide an authentication method (such as an API key, AD token, or credential object), initialization will fail.<\/p>\n<p>Users updating to this version who previously relied on the default fallback might see a <code>ServiceInitializationError<\/code> with the message: <code>Please provide either api_key, ad_token, ad_token_provider, credential or a client.<\/code> This error indicates that the SDK now requires you to explicitly pass one of the supported authentication options during service creation.<\/p>\n<p>This change promotes better coding practices by making authentication explicit, reducing hidden dependencies, and aligning with Azure&#8217;s security guidelines.<\/p>\n<h2><strong>How to Update Your Code<\/strong><\/h2>\n<p>To resolve this, update your code to pass an explicit authentication method. If you want to continue using a credential-based approach (similar to the old fallback), you can instantiate a specific credential type from the Azure Identity library and pass it to the service constructor.<\/p>\n<p>For example, change from the old implicit fallback:<\/p>\n<pre class=\"prettyprint language-python\"><code class=\"language-python\">chat_service = AzureChatCompletion()<\/code><\/pre>\n<p>To an explicit credential, such as <code>AzureCliCredential<\/code> (or any other suitable type like <code>ManagedIdentityCredential<\/code> for Azure-hosted apps):<\/p>\n<pre class=\"prettyprint language-python\"><code class=\"language-python\">from azure.identity import AzureCliCredential\r\n\r\nchat_service = AzureChatCompletion(credential=AzureCliCredential())  # Or use another credential type<\/code><\/pre>\n<p>Other options include providing an <code>api_key<\/code>, <code>ad_token<\/code>, <code>ad_token_provider<\/code>, or a pre-configured client. Choose the one that best fits your environment.<\/p>\n<p>Remember to import the necessary credential class from <code>azure.identity<\/code> and ensure your environment is set up accordingly (e.g., Azure CLI logged in for <code>AzureCliCredential<\/code>).<\/p>\n<h2><strong>Summary<\/strong><\/h2>\n<p>This update to the Semantic Kernel Python removes the <code>DefaultAzureCredential<\/code> fallback to encourage explicit and secure authentication, addressing potential issues in production while maintaining flexibility. By making a small code change, you can avoid initialization errors and align with best practices.<\/p>\n<p>We\u2019re always interested in hearing from you. If you have feedback, questions, or want to discuss further, feel free to reach out to us and the community on the <a href=\"https:\/\/github.com\/microsoft\/semantic-kernel\/discussions\">discussion boards<\/a> on GitHub! We would also love your support\u2014if you&#8217;ve enjoyed using Semantic Kernel, give us a star on <a href=\"https:\/\/github.com\/microsoft\/semantic-kernel\">GitHub<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In previous versions of the Semantic Kernel Python, the default fallback authentication mechanism for Azure services like AzureChatCompletion was DefaultAzureCredential from the Azure Identity library. This provided a convenient way to authenticate without explicitly passing credentials, especially during development. However, with the latest package version 1.36.0, this fallback is being removed to encourage more secure [&hellip;]<\/p>\n","protected":false},"author":156732,"featured_media":5001,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[17,34,1],"tags":[],"class_list":["post-4988","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-announcements","category-python-2","category-semantic-kernel"],"acf":[],"blog_post_summary":"<p>In previous versions of the Semantic Kernel Python, the default fallback authentication mechanism for Azure services like AzureChatCompletion was DefaultAzureCredential from the Azure Identity library. This provided a convenient way to authenticate without explicitly passing credentials, especially during development. However, with the latest package version 1.36.0, this fallback is being removed to encourage more secure [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/agent-framework\/wp-json\/wp\/v2\/posts\/4988","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/agent-framework\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/agent-framework\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/agent-framework\/wp-json\/wp\/v2\/users\/156732"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/agent-framework\/wp-json\/wp\/v2\/comments?post=4988"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/agent-framework\/wp-json\/wp\/v2\/posts\/4988\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/agent-framework\/wp-json\/wp\/v2\/media\/5001"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/agent-framework\/wp-json\/wp\/v2\/media?parent=4988"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/agent-framework\/wp-json\/wp\/v2\/categories?post=4988"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/agent-framework\/wp-json\/wp\/v2\/tags?post=4988"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}