cancel
Showing results forย 
Search instead forย 
Did you mean:ย 
Machine Learning
Dive into the world of machine learning on the Databricks platform. Explore discussions on algorithms, model training, deployment, and more. Connect with ML enthusiasts and experts.
cancel
Showing results forย 
Search instead forย 
Did you mean:ย 

Error 401: "Missing authorization details for accessing model serving endpoints" with OAuth Token on

gustavocavsanto
New Contributor

I am trying to generate an OAuth token for my Azure Databricks workspace to access a model serving API in production. The code Iโ€™m using generates a token successfully, but I keep receiving a 401 error with the message "Missing authorization details for accessing model serving endpoints" when I try to use it.

Here's the code I'm using:

 

import requests

# Azure Databricks and Managed Service Principal Details
client_id = "XXXX"  # Application ID
client_secret = "XXXXX"  # Client Secret
workspace_url = "XXXXXX"  # Databricks workspace URL

# Databricks-specific endpoint URL for token generation
token_endpoint_url = f"{workspace_url}/oidc/v1/token"

# Function to get OAuth access token with all-apis scope
def get_workspace_oauth_token():
    response = requests.post(
        token_endpoint_url,
        auth=(client_id, client_secret),
        data={
            "grant_type": "client_credentials",
            "scope": "all-apis"
        }
    )
    response.raise_for_status()  # Check for request errors
    return response.json(), response.json().get("access_token")

# Generate the access token
response, access_token = get_workspace_oauth_token()
print("OAuth token generated successfully:", access_token)

 

The OAuth token seems to be generated without any issues. Iโ€™ve also ensured that my Service Principal has the necessary permissions to access the model serving endpoint in the Databricks workspace.

However, when using this token to call the model serving API endpoint, I get the following response:

 

{
    "error_code": 401,
    "message": "Missing authorization details for accessing model serving endpoints"
}

 

Additional Context: I have already assigned permissions to the Service Principal in Databricks. Iโ€™m using the all-apis scope to cover the model serving endpoint. Has anyone encountered this issue or have suggestions on what could be causing the 401 error?

1 REPLY 1

Walter_C
Databricks Employee
Databricks Employee

You might need to follow steps in https://docs.databricks.com/en/machine-learning/model-serving/route-optimization.html#query-route-op... on how to fetch an OAuth token programmatically

Connect with Databricks Users in Your Area

Join a Regional User Group to connect with local Databricks users. Events will be happening in your city, and you wonโ€™t want to miss the chance to attend and share knowledge.

If there isnโ€™t a group near you, start one and help create a community that brings people together.

Request a New Group