Deploy models using Azure CLI and Bicep
This article refers to the Microsoft Foundry (new) portal.
If you’re currently using an Azure AI Inference beta SDK with Microsoft Foundry Models or Azure OpenAI service, we strongly recommend that you transition to the generally available OpenAI/v1 API, which uses an OpenAI stable SDK.For more information on how to migrate to the OpenAI/v1 API by using an SDK in your programming language of choice, see Migrate from Azure AI Inference SDK to OpenAI SDK.
Prerequisites
To complete this article, you need the following:- An Azure subscription. If you’re using GitHub Models, you can upgrade your experience and create an Azure subscription in the process. For more information, see Upgrade from GitHub Models to Foundry Models.
- A Foundry project. This project type is managed under a Foundry resource (formerly known as Azure AI Services resource). If you don’t have a Foundry project, see Create a project for Microsoft Foundry.
- Azure role-based access control (RBAC) permissions to create and manage deployments. You need the Cognitive Services Contributor role or equivalent permissions for the Foundry resource.
- Foundry Models from partners and community require access to Azure Marketplace. Ensure you have the permissions required to subscribe to model offerings. Foundry Models sold directly by Azure don’t have this requirement.
-
Install the Azure CLI (version 2.60 or later) and the
cognitiveservicesextension. -
Some commands in this tutorial use the
jqtool, which might not be installed on your system. For installation instructions, see Downloadjq. -
Identify the following information:
- Your Azure subscription ID
- Your Foundry resource name
- The resource group where you deployed the Foundry resource
Add models
To add a model, first identify the model that you want to deploy. Query the available models as follows:-
Sign in to your Azure subscription.
-
If you have more than one subscription, select the subscription where your resource is located.
-
Set the following environment variables with the name of the Foundry resource you plan to use and resource group.
-
If you haven’t created a Foundry resource yet, create one.
Reference: az cognitiveservices account
-
Check which models are available to you and under which SKU. SKUs, also known as deployment types, define how Azure infrastructure processes requests. Models might offer different deployment types. The following command lists all the model definitions available:
The output includes available models with their properties:Reference: az cognitiveservices account list-models
-
Identify the model you want to deploy. You need the properties
name,format,version, andsku. The propertyformatindicates the provider offering the model. Depending on the type of deployment, you might also need capacity. -
Add the model deployment to the resource. The following example adds
Phi-4-mini-instruct:Reference: az cognitiveservices account deployment -
Verify the deployment completed successfully:
The output should display
"Succeeded". The model is ready to use after provisioning completes. Reference: az cognitiveservices account list-models
Use the model
This section is identical for both the CLI and Bicep approaches.
model and insert the model deployment name you created. You can programmatically get the URI for the inference endpoint by using the following code:
Inference endpoint
models. For example: https://<resource>.services.ai.azure.com/models. See the Azure AI Model Inference API reference for all supported operations.
Inference keys
Manage deployments
You can see all the deployments available using the CLI:-
Run the following command to see all the active deployments:
Reference: az cognitiveservices account deployment list
-
You can see the details of a given deployment:
Reference: az cognitiveservices account deployment show
-
You can delete a given deployment as follows:
Reference: az cognitiveservices account deployment delete
- Install the Azure CLI.
-
Identify the following information:
- Your Azure subscription ID
- Your Foundry resource (formerly known as Azure AI Services resource) name
- The resource group where the Foundry resource is deployed
-
The model name, provider, version, and SKU you want to deploy. You can use the Foundry portal or the Azure CLI to find this information. In this example, you deploy the following model:
- Model name:
Phi-4-mini-instruct - Provider:
Microsoft - Version:
1 - Deployment type: Global standard
- Model name:
Set up the environment
The example in this article is based on code samples contained in the Azure-Samples/azureai-model-inference-bicep repository. To run the commands locally without having to copy or paste file content, clone the repository:Permissions required to subscribe to Models from Partners and Community
Foundry Models from partners and community available for deployment (for example, Cohere models) require Azure Marketplace. Model providers define the license terms and set the price for use of their models using Azure Marketplace. When deploying third-party models, ensure you have the following permissions in your account:On the Azure subscription:
Microsoft.MarketplaceOrdering/agreements/offers/plans/readMicrosoft.MarketplaceOrdering/agreements/offers/plans/sign/actionMicrosoft.MarketplaceOrdering/offerTypes/publishers/offers/plans/agreements/readMicrosoft.Marketplace/offerTypes/publishers/offers/plans/agreements/readMicrosoft.SaaS/register/actionOn the resource group—to create and use the SaaS resource:
Microsoft.SaaS/resources/readMicrosoft.SaaS/resources/write-
Use the template
ai-services-deployment-template.bicepto describe model deployments: ai-services-deployment-template.bicep -
Run the deployment:
-
Verify the deployment completed successfully:
The output should display
"Succeeded".
Use the model
This section is identical for both the CLI and Bicep approaches.
model and insert the model deployment name you created. You can programmatically get the URI for the inference endpoint by using the following code:
Inference endpoint
models. For example: https://<resource>.services.ai.azure.com/models. See the Azure AI Model Inference API reference for all supported operations.
Inference keys
Troubleshooting
| Error | Cause | Resolution |
|---|---|---|
| Quota exceeded | Your subscription reached the deployment quota for the selected SKU or region. | Check your quota in the Foundry portal or request an increase through Azure support. |
| Authorization failed | The identity used doesn’t have the required RBAC role. | Assign the Cognitive Services Contributor role on the Foundry resource. |
| Model not available | The model isn’t available in your region or subscription. | Run az cognitiveservices account list-models to check available models and regions. |
| Extension not found | The cognitiveservices CLI extension isn’t installed. | Run az extension add -n cognitiveservices to install the extension. |