<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Authentication error when calling Databricks foundational model endpoint from pandas udf in Generative AI</title>
    <link>https://community.databricks.com/t5/generative-ai/authentication-error-when-calling-databricks-foundational-model/m-p/132124#M1153</link>
    <description>&lt;P&gt;Hey&amp;nbsp;&lt;A id="link_7" class="lia-link-navigation lia-page-link lia-user-name-link" href="https://community.databricks.com/t5/user/viewprofilepage/user-id/178191" target="_self" aria-label="View Profile of DinoSaluzzi"&gt;&lt;SPAN class=""&gt;DinoSaluzzi&lt;/SPAN&gt;&lt;/A&gt;&amp;nbsp;- Thanks for reaching out!&lt;/P&gt;
&lt;P class="qt3gz91 paragraph"&gt;The error message you're seeing—&lt;CODE class="qt3gz9f"&gt;ValueError: default auth: runtime: default auth: cannot configure default credentials&lt;/CODE&gt;—reflects a stricter enforcement in how authentication happens within Spark worker nodes running pandas UDFs on Databricks. This is not an isolated issue but a byproduct of growing security and compliance standards for accessing Databricks-hosted foundation model endpoints.&lt;/P&gt;
&lt;P class="qt3gz91 paragraph"&gt;&amp;nbsp;&lt;/P&gt;
&lt;H4 class="_7uu25p0 qt3gz9c _7pq7t612 heading4 _7uu25p1"&gt;Why This Error Occurs&lt;/H4&gt;
&lt;UL class="qt3gz97 qt3gz92"&gt;
&lt;LI class="qt3gz9a"&gt;
&lt;P class="qt3gz91 paragraph"&gt;When you invoke a Databricks foundational model API (such as through the ChatDatabricks wrapper) inside a pandas UDF, the code gets executed on separate Spark worker nodes—not on the main driver process.&lt;/P&gt;
&lt;/LI&gt;
&lt;LI class="qt3gz9a"&gt;
&lt;P class="qt3gz91 paragraph"&gt;These worker nodes do &lt;STRONG&gt;not&lt;/STRONG&gt; inherit your interactive (user) session credentials or SSO context by default. Any authentication previously accessible due to implicit session passing, workspace defaults, or inherited environment variables is &lt;STRONG&gt;not reliably available&lt;/STRONG&gt; to workers.&lt;/P&gt;
&lt;/LI&gt;
&lt;LI class="qt3gz9a"&gt;
&lt;P class="qt3gz91 paragraph"&gt;Your workflow may have functioned in the past because of less strict authentication checks or side effects in how worker environments were initialized. Recent updates to authentication libraries or Databricks runtime safety controls now enforce that every API call from a worker node must have explicit, valid credentials provided at call time.&lt;/P&gt;
&lt;/LI&gt;
&lt;LI class="qt3gz9a"&gt;
&lt;P class="qt3gz91 paragraph"&gt;As a result, code that doesn't supply a credential explicitly to the API call from within each worker will now fail with errors like the one you attached.&lt;/P&gt;
&lt;/LI&gt;
&lt;/UL&gt;
&lt;H3 class="_7uu25p0 qt3gz9c _7pq7t612 heading3 _7uu25p1"&gt;Recommended Approach: How to Properly Authenticate in Worker Nodes&lt;/H3&gt;
&lt;P class="qt3gz91 paragraph"&gt;To comply with Databricks' security best practices and ensure pandas UDFs (i.e., the worker nodes) can call foundational model endpoints:&lt;/P&gt;
&lt;OL class="qt3gz92"&gt;
&lt;LI class="qt3gz9a"&gt;
&lt;P class="qt3gz91 paragraph"&gt;&lt;STRONG&gt;Never rely on implicit session credentials inside UDFs.&lt;/STRONG&gt; Every worker acts as a clean process without your user/session context.&lt;/P&gt;
&lt;/LI&gt;
&lt;LI class="qt3gz9a"&gt;
&lt;P class="qt3gz91 paragraph"&gt;&lt;STRONG&gt;Use a Machine-to-Machine OAuth Token (Preferred for Production):&lt;/STRONG&gt;&lt;/P&gt;
&lt;UL class="qt3gz98 qt3gz92"&gt;
&lt;LI class="qt3gz9a"&gt;Register a service principal with appropriate permissions.&lt;/LI&gt;
&lt;LI class="qt3gz9a"&gt;Store OAuth credentials (client ID/secret) securely in a Databricks secret scope.&lt;/LI&gt;
&lt;LI class="qt3gz9a"&gt;Distribute/obtain a fresh OAuth token inside workers, typically by accessing secrets either before the UDF or within it.&lt;/LI&gt;
&lt;/UL&gt;
&lt;/LI&gt;
&lt;LI class="qt3gz9a"&gt;
&lt;P class="qt3gz91 paragraph"&gt;&lt;STRONG&gt;Alternatively, Pass a Service Principal PAT Token (For Dev/Testing):&lt;/STRONG&gt;&lt;/P&gt;
&lt;UL class="qt3gz98 qt3gz92"&gt;
&lt;LI class="qt3gz9a"&gt;Create a PAT token for a service principal (not a personal/user PAT).&lt;/LI&gt;
&lt;LI class="qt3gz9a"&gt;Store it in a Databricks secret scope.&lt;/LI&gt;
&lt;LI class="qt3gz9a"&gt;Retrieve the token inside your pandas UDF (or broadcast it to all workers).&lt;/LI&gt;
&lt;/UL&gt;
&lt;DIV class="go8b9g1 _7pq7t6c8"&gt;
&lt;PRE&gt;&lt;CODE class="markdown-code-python qt3gz9e hljs language-python _1ymogdh2"&gt;token = dbutils.secrets.get(scope=&lt;SPAN class="hljs-string"&gt;"my-secret-scope"&lt;/SPAN&gt;, key=&lt;SPAN class="hljs-string"&gt;"FMAPI_TOKEN"&lt;/SPAN&gt;)
&lt;SPAN class="hljs-keyword"&gt;def&lt;/SPAN&gt; &lt;SPAN class="hljs-title function_"&gt;my_udf&lt;/SPAN&gt;(&lt;SPAN class="hljs-params"&gt;...&lt;/SPAN&gt;):
    headers = {&lt;SPAN class="hljs-string"&gt;"Authorization"&lt;/SPAN&gt;: &lt;SPAN class="hljs-string"&gt;f"Bearer &lt;SPAN class="hljs-subst"&gt;{token}&lt;/SPAN&gt;"&lt;/SPAN&gt;}
    &lt;SPAN class="hljs-comment"&gt;# Make your endpoint call using these headers&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;/DIV&gt;
&lt;/LI&gt;
&lt;LI class="qt3gz9a"&gt;
&lt;P class="qt3gz91 paragraph"&gt;&lt;STRONG&gt;Set Environment Variables or Use Spark Broadcasts (Optional):&lt;/STRONG&gt;&lt;/P&gt;
&lt;UL class="qt3gz98 qt3gz92"&gt;
&lt;LI class="qt3gz9a"&gt;If environment variables are required for a library to detect auth, set them programmatically in each worker process within your UDF.&lt;/LI&gt;
&lt;/UL&gt;
&lt;/LI&gt;
&lt;LI class="qt3gz9a"&gt;
&lt;P class="qt3gz91 paragraph"&gt;&lt;STRONG&gt;Never embed credentials in code or notebooks.&lt;/STRONG&gt; Use Databricks secret scopes or environment configuration for sensitive information.&lt;/P&gt;
&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here are some resources (switch clouds with dropdown on top right):&lt;/P&gt;
&lt;P&gt;&lt;A href="https://docs.databricks.com/aws/en/machine-learning/model-serving/score-foundation-models" target="_blank"&gt;https://docs.databricks.com/aws/en/machine-learning/model-serving/score-foundation-models&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://docs.databricks.com/aws/en/machine-learning/model-serving/score-custom-model-endpoints" target="_blank"&gt;https://docs.databricks.com/aws/en/machine-learning/model-serving/score-custom-model-endpoints&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://docs.databricks.com/aws/en/admin/users-groups/best-practices" target="_blank"&gt;https://docs.databricks.com/aws/en/admin/users-groups/best-practices&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;H4 class="_7uu25p0 qt3gz9c _7pq7t612 heading4 _7uu25p1"&gt;&amp;nbsp;&lt;/H4&gt;</description>
    <pubDate>Tue, 16 Sep 2025 14:22:38 GMT</pubDate>
    <dc:creator>sarahbhord</dc:creator>
    <dc:date>2025-09-16T14:22:38Z</dc:date>
    <item>
      <title>Authentication error when calling Databricks foundational model endpoint from pandas udf</title>
      <link>https://community.databricks.com/t5/generative-ai/authentication-error-when-calling-databricks-foundational-model/m-p/131497#M1134</link>
      <description>&lt;P&gt;Hi everyone!&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;I’m running into an authentication error when trying to call a Databricks foundational model endpoint inside a pandas UDF. I’m using the ChatDatabricks wrapper to make completions, and this setup was working properly until last week (image attached).&lt;BR /&gt;Has something changed in how pandas UDF worker nodes access endpoints or handle authentication? What is the correct way to authenticate and make these calls from within workers?&lt;BR /&gt;Any advice, recommended practices, or documentation would be greatly appreciated!&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Wed, 10 Sep 2025 08:59:50 GMT</pubDate>
      <guid>https://community.databricks.com/t5/generative-ai/authentication-error-when-calling-databricks-foundational-model/m-p/131497#M1134</guid>
      <dc:creator>DinoSaluzzi</dc:creator>
      <dc:date>2025-09-10T08:59:50Z</dc:date>
    </item>
    <item>
      <title>Re: Authentication error when calling Databricks foundational model endpoint from pandas udf</title>
      <link>https://community.databricks.com/t5/generative-ai/authentication-error-when-calling-databricks-foundational-model/m-p/132124#M1153</link>
      <description>&lt;P&gt;Hey&amp;nbsp;&lt;A id="link_7" class="lia-link-navigation lia-page-link lia-user-name-link" href="https://community.databricks.com/t5/user/viewprofilepage/user-id/178191" target="_self" aria-label="View Profile of DinoSaluzzi"&gt;&lt;SPAN class=""&gt;DinoSaluzzi&lt;/SPAN&gt;&lt;/A&gt;&amp;nbsp;- Thanks for reaching out!&lt;/P&gt;
&lt;P class="qt3gz91 paragraph"&gt;The error message you're seeing—&lt;CODE class="qt3gz9f"&gt;ValueError: default auth: runtime: default auth: cannot configure default credentials&lt;/CODE&gt;—reflects a stricter enforcement in how authentication happens within Spark worker nodes running pandas UDFs on Databricks. This is not an isolated issue but a byproduct of growing security and compliance standards for accessing Databricks-hosted foundation model endpoints.&lt;/P&gt;
&lt;P class="qt3gz91 paragraph"&gt;&amp;nbsp;&lt;/P&gt;
&lt;H4 class="_7uu25p0 qt3gz9c _7pq7t612 heading4 _7uu25p1"&gt;Why This Error Occurs&lt;/H4&gt;
&lt;UL class="qt3gz97 qt3gz92"&gt;
&lt;LI class="qt3gz9a"&gt;
&lt;P class="qt3gz91 paragraph"&gt;When you invoke a Databricks foundational model API (such as through the ChatDatabricks wrapper) inside a pandas UDF, the code gets executed on separate Spark worker nodes—not on the main driver process.&lt;/P&gt;
&lt;/LI&gt;
&lt;LI class="qt3gz9a"&gt;
&lt;P class="qt3gz91 paragraph"&gt;These worker nodes do &lt;STRONG&gt;not&lt;/STRONG&gt; inherit your interactive (user) session credentials or SSO context by default. Any authentication previously accessible due to implicit session passing, workspace defaults, or inherited environment variables is &lt;STRONG&gt;not reliably available&lt;/STRONG&gt; to workers.&lt;/P&gt;
&lt;/LI&gt;
&lt;LI class="qt3gz9a"&gt;
&lt;P class="qt3gz91 paragraph"&gt;Your workflow may have functioned in the past because of less strict authentication checks or side effects in how worker environments were initialized. Recent updates to authentication libraries or Databricks runtime safety controls now enforce that every API call from a worker node must have explicit, valid credentials provided at call time.&lt;/P&gt;
&lt;/LI&gt;
&lt;LI class="qt3gz9a"&gt;
&lt;P class="qt3gz91 paragraph"&gt;As a result, code that doesn't supply a credential explicitly to the API call from within each worker will now fail with errors like the one you attached.&lt;/P&gt;
&lt;/LI&gt;
&lt;/UL&gt;
&lt;H3 class="_7uu25p0 qt3gz9c _7pq7t612 heading3 _7uu25p1"&gt;Recommended Approach: How to Properly Authenticate in Worker Nodes&lt;/H3&gt;
&lt;P class="qt3gz91 paragraph"&gt;To comply with Databricks' security best practices and ensure pandas UDFs (i.e., the worker nodes) can call foundational model endpoints:&lt;/P&gt;
&lt;OL class="qt3gz92"&gt;
&lt;LI class="qt3gz9a"&gt;
&lt;P class="qt3gz91 paragraph"&gt;&lt;STRONG&gt;Never rely on implicit session credentials inside UDFs.&lt;/STRONG&gt; Every worker acts as a clean process without your user/session context.&lt;/P&gt;
&lt;/LI&gt;
&lt;LI class="qt3gz9a"&gt;
&lt;P class="qt3gz91 paragraph"&gt;&lt;STRONG&gt;Use a Machine-to-Machine OAuth Token (Preferred for Production):&lt;/STRONG&gt;&lt;/P&gt;
&lt;UL class="qt3gz98 qt3gz92"&gt;
&lt;LI class="qt3gz9a"&gt;Register a service principal with appropriate permissions.&lt;/LI&gt;
&lt;LI class="qt3gz9a"&gt;Store OAuth credentials (client ID/secret) securely in a Databricks secret scope.&lt;/LI&gt;
&lt;LI class="qt3gz9a"&gt;Distribute/obtain a fresh OAuth token inside workers, typically by accessing secrets either before the UDF or within it.&lt;/LI&gt;
&lt;/UL&gt;
&lt;/LI&gt;
&lt;LI class="qt3gz9a"&gt;
&lt;P class="qt3gz91 paragraph"&gt;&lt;STRONG&gt;Alternatively, Pass a Service Principal PAT Token (For Dev/Testing):&lt;/STRONG&gt;&lt;/P&gt;
&lt;UL class="qt3gz98 qt3gz92"&gt;
&lt;LI class="qt3gz9a"&gt;Create a PAT token for a service principal (not a personal/user PAT).&lt;/LI&gt;
&lt;LI class="qt3gz9a"&gt;Store it in a Databricks secret scope.&lt;/LI&gt;
&lt;LI class="qt3gz9a"&gt;Retrieve the token inside your pandas UDF (or broadcast it to all workers).&lt;/LI&gt;
&lt;/UL&gt;
&lt;DIV class="go8b9g1 _7pq7t6c8"&gt;
&lt;PRE&gt;&lt;CODE class="markdown-code-python qt3gz9e hljs language-python _1ymogdh2"&gt;token = dbutils.secrets.get(scope=&lt;SPAN class="hljs-string"&gt;"my-secret-scope"&lt;/SPAN&gt;, key=&lt;SPAN class="hljs-string"&gt;"FMAPI_TOKEN"&lt;/SPAN&gt;)
&lt;SPAN class="hljs-keyword"&gt;def&lt;/SPAN&gt; &lt;SPAN class="hljs-title function_"&gt;my_udf&lt;/SPAN&gt;(&lt;SPAN class="hljs-params"&gt;...&lt;/SPAN&gt;):
    headers = {&lt;SPAN class="hljs-string"&gt;"Authorization"&lt;/SPAN&gt;: &lt;SPAN class="hljs-string"&gt;f"Bearer &lt;SPAN class="hljs-subst"&gt;{token}&lt;/SPAN&gt;"&lt;/SPAN&gt;}
    &lt;SPAN class="hljs-comment"&gt;# Make your endpoint call using these headers&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;/DIV&gt;
&lt;/LI&gt;
&lt;LI class="qt3gz9a"&gt;
&lt;P class="qt3gz91 paragraph"&gt;&lt;STRONG&gt;Set Environment Variables or Use Spark Broadcasts (Optional):&lt;/STRONG&gt;&lt;/P&gt;
&lt;UL class="qt3gz98 qt3gz92"&gt;
&lt;LI class="qt3gz9a"&gt;If environment variables are required for a library to detect auth, set them programmatically in each worker process within your UDF.&lt;/LI&gt;
&lt;/UL&gt;
&lt;/LI&gt;
&lt;LI class="qt3gz9a"&gt;
&lt;P class="qt3gz91 paragraph"&gt;&lt;STRONG&gt;Never embed credentials in code or notebooks.&lt;/STRONG&gt; Use Databricks secret scopes or environment configuration for sensitive information.&lt;/P&gt;
&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here are some resources (switch clouds with dropdown on top right):&lt;/P&gt;
&lt;P&gt;&lt;A href="https://docs.databricks.com/aws/en/machine-learning/model-serving/score-foundation-models" target="_blank"&gt;https://docs.databricks.com/aws/en/machine-learning/model-serving/score-foundation-models&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://docs.databricks.com/aws/en/machine-learning/model-serving/score-custom-model-endpoints" target="_blank"&gt;https://docs.databricks.com/aws/en/machine-learning/model-serving/score-custom-model-endpoints&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://docs.databricks.com/aws/en/admin/users-groups/best-practices" target="_blank"&gt;https://docs.databricks.com/aws/en/admin/users-groups/best-practices&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;H4 class="_7uu25p0 qt3gz9c _7pq7t612 heading4 _7uu25p1"&gt;&amp;nbsp;&lt;/H4&gt;</description>
      <pubDate>Tue, 16 Sep 2025 14:22:38 GMT</pubDate>
      <guid>https://community.databricks.com/t5/generative-ai/authentication-error-when-calling-databricks-foundational-model/m-p/132124#M1153</guid>
      <dc:creator>sarahbhord</dc:creator>
      <dc:date>2025-09-16T14:22:38Z</dc:date>
    </item>
  </channel>
</rss>

