You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: articles/ai-foundry/model-inference/how-to/quickstart-ai-project.md
+12-11Lines changed: 12 additions & 11 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -14,17 +14,17 @@ recommendations: false
14
14
15
15
# Configure your AI project to use Azure AI model inference
16
16
17
-
If you already have an AI project in an existing AI Hub, models via "Models as a Service" are by default deployed inside of your project as stand-alone endpoints. Each model deployment has its own set of URI and credentials to access it. Azure OpenAI models are deployed to Azure AI Services resource or to the Azure OpenAI Service resource.
17
+
If you already have an AI project in Azure AI Foundry, the model catalog deploys models from third-party model providers as stand-alone endpoints in your project by default. Each model deployment has its own set of URI and credentials to access it. On the other hand, Azure OpenAI models are deployed to Azure AI Services resource or to the Azure OpenAI Service resource.
18
18
19
-
You can configure the AI project to connect with the Azure AI model inference in Azure AI services. Once configured, **deployments of Models as a Service models happen to the connected Azure AI Services resource** instead to the project itself, giving you a single set of endpoint and credential to access all the models deployed in Azure AI Foundry.
19
+
You can change this behavior and deploy both types of models to Azure AI Services resources using Azure AI model inference. Once configured, **deployments of Models as a Service models supporting pay-as-you-go billing happen to the connected Azure AI Services resource** instead to the project itself, giving you a single set of endpoint and credential to access all the models deployed in Azure AI Foundry. You can manage Azure OpenAI and third-party model providers models in the same way.
20
20
21
21
Additionally, deploying models to Azure AI model inference brings the extra benefits of:
> *[Key-less authentication](configure-entra-id.md) with role-based access control.
28
28
29
29
In this article, you learn how to configure your project to use models deployed in Azure AI model inference in Azure AI services.
30
30
@@ -104,7 +104,7 @@ For each model you want to deploy under Azure AI model inference, follow these s
104
104
105
105
6. You can configure the deployment settings at this time. By default, the deployment receives the name of the model you're deploying. The deployment name is used in the `model` parameter for request to route to this particular model deployment. It allows you to configure specific names for your models when you attach specific configurations. For instance, `o1-preview-safe` for a model with a strict content safety content filter.
106
106
107
-
7. We automatically select an Azure AI Services connection depending on your project because you have turned on the feature **Deploy models to Azure AI model inference service**. Use the **Customize** option to change the connection based on your needs. If you're deploying under the **Standard** deployment type, the models need to be available in the region of the Azure AI Services resource.
107
+
7. We automatically select an Azure AI Services connection depending on your project because you turned on the feature **Deploy models to Azure AI model inference service**. Use the **Customize** option to change the connection based on your needs. If you're deploying under the **Standard** deployment type, the models need to be available in the region of the Azure AI Services resource.
108
108
109
109
:::image type="content" source="../media/add-model-deployments/models-deploy-customize.png" alt-text="Screenshot showing how to customize the deployment if needed." lightbox="../media/add-model-deployments/models-deploy-customize.png":::
110
110
@@ -152,7 +152,7 @@ Although you configured the project to use the Azure AI model inference, existin
152
152
153
153
### Upgrade your code with the new endpoint
154
154
155
-
Once the models are deployed under Azure AI Services, you can upgrade your code to use the Azure AI model inference endpoint. The main difference between how Serverless API endpoints and Azure AI model inference works reside in the endpoint URL and model parameter. While Serverless API Endpoints have set of URI and key per each model deployment, Azure AI model inference has only one for all of them.
155
+
Once the models are deployed under Azure AI Services, you can upgrade your code to use the Azure AI model inference endpoint. The main difference between how Serverless API endpoints and Azure AI model inference works reside in the endpoint URL and model parameter. While Serverless API Endpoints have a set of URI and key per each model deployment, Azure AI model inference has only one for all of them.
156
156
157
157
The following table summarizes the changes you have to introduce:
158
158
@@ -186,10 +186,11 @@ For each model deployed as Serverless API Endpoints, follow these steps:
186
186
187
187
## Limitations
188
188
189
-
Azure AI model inference in Azure AI Services gives users access to flagship models in the Azure AI model catalog. However, only models supporting pay-as-you-go billing (Models as a Service) are available for deployment.
189
+
Consider the following limitations when configuring your project to use Azure AI model inference:
190
190
191
-
Models requiring compute quota from your subscription (Managed Compute), including custom models, can only be deployed within a given project as Managed Online Endpoints and continue to be accessible using their own set of endpoint URI and credentials.
191
+
* Only models supporting pay-as-you-go billing (Models as a Service) are available for deployment to Azure AI model inference. Models requiring compute quota from your subscription (Managed Compute), including custom models, can only be deployed within a given project as Managed Online Endpoints and continue to be accessible using their own set of endpoint URI and credentials.
192
+
* Models available as both pay-as-you-go billing and managed compute offerings are, by default, deployed to Azure AI model inference in Azure AI services resources. Azure AI Foundry portal doesn't offer a way to deploy them to Managed Online Endpoints. You have to turn off the feature mentioned at [Configure the project to use Azure AI model inference](#configure-the-project-to-use-azure-ai-model-inference) or use the Azure CLI/Azure ML SDK/ARM templates to perform the deployment.
192
193
193
194
## Next steps
194
195
195
-
*[Add more models](create-model-deployments.md) to your endpoint.
196
+
*[Add more models](create-model-deployments.md) to your endpoint.
Explore our [samples](https://github.com/Azure/azure-sdk-for-java/tree/main/sdk/ai/azure-ai-inference/src/samples) and read the [API reference documentation](https://aka.ms/azsdk/azure-ai-inference/java/reference) to get yourself started.
117
+
86
118
# [REST](#tab/rest)
87
119
88
-
Use the reference section to explore the API design and which parameters are available and indicate authentication token in the header `Authorization`. For example, the reference section for [Chat completions](reference-model-inference-chat-completions.md) details how to use the route `/chat/completions` to generate predictions based on chat-formatted instructions. Notice that the path `/models` is included to the root of the URL:
120
+
Use the reference section to explore the API design and which parameters are available and indicate authentication token in the header `Authorization`. For example, the reference section for [Chat completions](../../../ai-studio/reference/reference-model-inference-chat-completions.md) details how to use the route `/chat/completions` to generate predictions based on chat-formatted instructions. Notice that the path `/models` is included to the root of the URL:
89
121
90
122
__Request__
91
123
@@ -94,4 +126,10 @@ POST models/chat/completions?api-version=2024-04-01-preview
94
126
Authorization: Bearer <bearer-token>
95
127
Content-Type: application/json
96
128
```
97
-
---
129
+
130
+
For testing purposes, the easiest way to get a valid token for your user account is to use the Azure CLI. In a console, run the following Azure CLI command:
131
+
132
+
```azurecli
133
+
az account get-access-token --resource https://cognitiveservices.azure.com --query "accessToken" --output tsv
### Options for credential when using Microsoft Entra ID
11
+
12
+
`DefaultAzureCredential` is an opinionated, ordered sequence of mechanisms for authenticating to Microsoft Entra ID. Each authentication mechanism is a class derived from the `TokenCredential` class and is known as a credential. At runtime, `DefaultAzureCredential` attempts to authenticate using the first credential. If that credential fails to acquire an access token, the next credential in the sequence is attempted, and so on, until an access token is successfully obtained. In this way, your app can use different credentials in different environments without writing environment-specific code.
13
+
14
+
When the preceding code runs on your local development workstation, it looks in the environment variables for an application service principal or at locally installed developer tools, such as Visual Studio, for a set of developer credentials. Either approach can be used to authenticate the app to Azure resources during local development.
15
+
16
+
When deployed to Azure, this same code can also authenticate your app to other Azure resources. `DefaultAzureCredential` can retrieve environment settings and managed identity configurations to authenticate to other services automatically.
17
+
18
+
### Best practices
19
+
20
+
* Use deterministic credentials in production environments: Strongly consider moving from `DefaultAzureCredential` to one of the following deterministic solutions on production environments:
21
+
22
+
* A specific `TokenCredential` implementation, such as `ManagedIdentityCredential`. See the [Derived list for options](/dotnet/api/azure.core.tokencredential#definition).
23
+
* A pared-down `ChainedTokenCredential` implementation optimized for the Azure environment in which your app runs. `ChainedTokenCredential` essentially creates a specific allowlist of acceptable credential options, such as `ManagedIdentity` for production and `VisualStudioCredential` for development.
24
+
25
+
* Configure system-assigned or user-assigned managed identities to the Azure resources where your code is running if possible. Configure Microsoft Entra ID access to those specific identities.
The example in this article is based on code samples contained in the [Azure-Samples/azureai-model-inference-bicep](https://github.com/Azure-Samples/azureai-model-inference-bicep) repository. To run the commands locally without having to copy or paste file content, use the following commands to clone the repository and go to the folder for your coding language:
> Notice that this template can take the parameter `allowKeys` which, when `false` will disable the use of keys in the resource. This configuration is optional.
51
+
52
+
2. Use the template `modules/role-assignment-template.bicep` to describe a role assignment in Azure:
7. The template outputs the Azure AI model inference endpoint that you can use to consume any of the model deployments you have created.
93
+
94
+
95
+
## Use Microsoft Entra ID in your code
96
+
97
+
Once you configured Microsoft Entra ID in your resource, you need to update your code to use it when consuming the inference endpoint. The following example shows how to use a chat completions model:
## Disable key-based authentication in the resource
106
+
107
+
Disabling key-based authentication is advisable when you implemented Microsoft Entra ID and fully addressed compatibility or fallback concerns in all the applications that consume the service.
* The resource group where the Azure AI Services resource is deployed.
22
+
23
+
24
+
## Configure Microsoft Entra ID for inference
25
+
26
+
Follow these steps to configure Microsoft Entra ID for inference in your Azure AI Services resource:
27
+
28
+
29
+
1. Log in into your Azure subscription:
30
+
31
+
```azurecli
32
+
az login
33
+
```
34
+
35
+
2. If you have more than one subscription, select the subscription where your resource is located:
36
+
37
+
```azurecli
38
+
az account set --subscription "<subscription-id>"
39
+
```
40
+
41
+
3. Set the following environment variables with the name of the Azure AI Services resource you plan to use and resource group.
42
+
43
+
```azurecli
44
+
ACCOUNT_NAME="<ai-services-resource-name>"
45
+
RESOURCE_GROUP="<resource-group>"
46
+
```
47
+
48
+
4. Get the full name of your resource:
49
+
50
+
```azurecli
51
+
RESOURCE_ID=$(az resource show -g $RESOURCE_GROUP -n $ACCOUNT_NAME --resource-type "Microsoft.CognitiveServices/accounts")
52
+
```
53
+
54
+
5. Get the object ID of the security principal you want to assign permissions to. The following example shows how to get the object ID associated with:
55
+
56
+
__Your own logged in account:__
57
+
58
+
```azurecli
59
+
OBJECT_ID=$(az ad signed-in-user show --query id --output tsv)
60
+
```
61
+
62
+
__A security group:__
63
+
64
+
```azurecli
65
+
OBJECT_ID=$(az ad group show --group "<group-name>" --query id --output tsv)
66
+
```
67
+
68
+
__A service principal:__
69
+
70
+
```azurecli
71
+
OBJECT_ID=$(az ad sp show --id "<service-principal-guid>" --query id --output tsv)
72
+
```
73
+
74
+
6. Assign the **Cognitive Services User** role to the service principal (scoped to the resource). By assigning a role, you're granting service principal access to this resource.
75
+
76
+
```azurecli
77
+
az role assignment create --assignee-object-id $OBJECT_ID --role "Cognitive Services User" --scope $RESOURCE_ID
78
+
```
79
+
80
+
8. The selected user can now use Microsoft Entra ID for inference.
81
+
82
+
> [!TIP]
83
+
> Keep in mind that Azure role assignments may take up to five minutes to propagate. Adding or removing users from a security group propagates immediately.
84
+
85
+
86
+
## Use Microsoft Entra ID in your code
87
+
88
+
Once Microsoft Entra ID is configured in your resource, you need to update your code to use it when consuming the inference endpoint. The following example shows how to use a chat completions model:
0 commit comments