I am using below code to get data from "Mistral-Nemo" model hosted as SaaS in Azure AI Foundry. It gives me below error:
Error: Operation returned an invalid status 'Bad Request'
Traceback (most recent call last):
File "c:\Users\guptswapmax\TestFalcon\TestFalcon.py", line 32, in <module>
response = client.complete(
~~~~~~~~~~~~~~~^
messages=[
^^^^^^^^^^
...<5 lines>...
model=model_name
^^^^^^^^^^^^^^^^
)
^
File "c:\Users\abc\TestFalcon\.venv\Lib\site-packages\azure\ai\inference\_patch.py", line 738, in complete
raise HttpResponseError(response=response)
azure.core.exceptions.HttpResponseError: Operation returned an invalid status 'Bad Request'
I have looked into the permissions and make sure my SP has required permissions and it also has "Coginitive Support User" and "Cognitive User Contributor" role and trying to implement using Service Principal
When i use the same code with Azure API Key and AzureKeyCredential it works. https://github.com/MicrosoftDocs/azure-ai-docs/blob/main/articles/ai-foundry/model-inference/includes/use-chat-completions/csharp.md
import os
from azure.ai.inference import ChatCompletionsClient
from azure.ai.inference.models import SystemMessage, UserMessage
from azure.identity import DefaultAzureCredential, ClientSecretCredential
import logging
from azure.core.pipeline.policies import HttpLoggingPolicy
endpoint = "https://abcdomain.services.ai.azure.com/models"
model_name = "Mistral-Nemo"
Client_Id = "xxxxxxxxxxxxxxxxxxxxxxxx"
Client_Secret = "xxxxxxxxxxxxxxxxxxx"
Tenant_Id = "xxxxxxxxxxxxxxxxxxxxxxxxx"
cred = ClientSecretCredential(
tenant_id=Tenant_Id,
client_id=Client_Id,
client_secret=Client_Secret
)
client = ChatCompletionsClient(
endpoint=endpoint,
credential=cred,
credential_scopes=["https://cognitiveservices.azure.com/.default"]
)
try:
result = client.complete(
messages=[
SystemMessage(content="You are a helpful assistant."),
UserMessage(content="How many languages are in the world?"),
],
temperature=0.8,
top_p=0.1,
max_tokens=2048,
stream=True,
model=model_name
)
except Exception as e:
print("Error:", e)


ClientSecretCredential?model=model_namebut you show code withmodel=model_deployment_name,- maybe you run wrong code. Maybe you run code with some mistake.