[Python] azure.core.exceptions.HttpResponseError: (None) Internal server error 500 - model...

Discussão em 'Python' iniciado por Stack, Maio 19, 2025.

  1. Stack

    Stack Membro Participativo

    I have Azure AI foundry hub which has private end point enabled and all other network is disabled on it. I also have Azure AI Project under hub which is used to deploy serverless endpoint model. When i use AzureKeyCredential("key") it works fine but when i use DefaultAzureCredential() it gives me error Internal Server error 500. I debugged and found that authentication is successful in case of DefaultAzureCredential and it uses AzureCLICredential to authenticate. I tried printing stack tace but is is not giving any detailed error information just 500 error.

    • Am i missing any permissions etc ?

    This works when i disable the Private Endpoint with DefaultAzureCredential

    But as soon as POST request goes it starts sending back 500 error code.
    azure.core.exceptions.HttpResponseError: (None) Internal server error


    import logging
    from azure.ai.inference import ChatCompletionsClient
    from azure.ai.inference.models import AssistantMessage, SystemMessage, UserMessage
    from azure.core.credentials import AzureKeyCredential
    from azure.identity import DefaultAzureCredential
    from azure.core.pipeline.policies import HttpLoggingPolicy


    endpoint = "https://abc.eastus.models.ai.azure.com"
    model_name = "se-Mistral-large"


    # It uses the DefaultAzureCredential to authenticate
    client = ChatCompletionsClient(
    endpoint=endpoint,
    credential=DefaultAzureCredential()
    )

    response = client.complete(
    messages=[
    {
    "role": "user",
    "content": "I am going to Paris, what should I see?"
    }
    ],
    max_tokens=2048,
    temperature=0.8,
    top_p=0.1,
    model=model_name
    )
    print(response.choices[0].message.content)


    This also returns 500 error

    credential = DefaultAzureCredential()
    token = credential.get_token("https://ml.azure.com/.default")
    client = ChatCompletionsClient(
    endpoint="https://abc.eastus.models.ai.azure.com",
    credential=AzureKeyCredential(token.token)
    )


    Printing the header body

    2025-05-15 16:37:43,989 - ERROR - Request Headers: {'Content-Type': 'application/json', 'Content-Length': '136', 'Accept': 'application/json', 'x-ms-client-request-id': 'e9e6ba1a-31aa-11f0-8e44-7c1e528244e5', , 'User-Agent': 'azsdk-python-ai-inference/1.0.0b9 Python/3.13.3 (Windows-2022Server-10.0.20348-SP0)', 'Authorization': 'Bearer token'}
    2025-05-15 16:37:44,005 - ERROR - Request Body: {"messages": [{"role": "user", "content": "I am going to London, what should I see?"}], "max_tokens": 2048, "model": "se-Mistral-large"}
    2025-05-15 16:37:44,006 - ERROR - Response Headers: {'Content-Length': '111', 'Content-Type': 'application/json', 'x-request-id': '6023e2cb-7220-4f9a-a439-5c84ea572f02', 'x-ms-error-reason': 'ExpressionValueEvaluationFailure', 'Request-Context': 'appId=cid-v1:38659f32-9fc9-4714-92e6-1412a97fbbfc', 'Date': 'Thu, 15 May 2025 16:37:43 GMT'}
    2025-05-15 16:37:44,007 - ERROR - Response Body: { "statusCode": 500, "message": "Internal server error", "activityId": "6023e2cb-7220-4f9a-a439-5c84ea572f02" }

    Continue reading...

Compartilhe esta Página