Deploy models as serverless API endpoints

In this article, you learn how to deploy a model from the model catalog as a serverless API with pay-as-you-go token-based billing.

Certain models in the model catalog can be deployed as a serverless API with pay-as-you-go billing. This kind of deployment provides a way to consume models as an API without hosting them on your subscription, while keeping the enterprise security and compliance that organizations need. This deployment option doesn't require quota from your subscription.

This article uses a Meta Llama model deployment for illustration. However, you can use the same steps to deploy any of the models in the model catalog that are available for serverless API deployment.

Prerequisites

  • An Azure subscription with a valid payment method. Free or trial Azure subscriptions won't work. If you don't have an Azure subscription, create a paid Azure account to begin.

  • An Azure Machine Learning workspace.

  • Azure role-based access controls (Azure RBAC) are used to grant access to operations in Azure Machine Learning. To perform the steps in this article, your user account must be assigned the Azure AI Developer role on the resource group. For more information on permissions, see Role-based access control in Azure Machine Learning.

  • You need to install the following software to work with Azure Machine Learning:

    You can use any compatible web browser to navigate Azure Machine Learning.

Find your model and model ID in the model catalog

  1. Sign in to Azure Machine Learning studio

  2. For models offered through the Azure Marketplace, ensure that your account has the Azure AI Developer role permissions on the resource group, or that you meet the permissions required to subscribe to model offerings.

    Models that are offered by non-Microsoft providers (for example, Llama and Mistral models) are billed through the Azure Marketplace. For such models, you're required to subscribe your workspace to the particular model offering. Models that are offered by Microsoft (for example, Phi-3 models) don't have this requirement, as billing is done differently. For details about billing for serverless deployment of models in the model catalog, see Billing for serverless APIs.

  3. Go to your workspace. To use the serverless API model deployment offering, your workspace must belong to one of the regions that are supported for serverless deployment for the particular model you want to deploy.

  4. Select Model catalog from the left sidebar and find the model card of the model you want to deploy. In this article, you select a Meta-Llama-3-8B-Instruct model.

    1. If you're deploying the model using Azure CLI, Python SDK, or ARM, copy the Model ID.

    Important

    Do not include the version when copying the Model ID. Serverless API endpoints always deploy the model's latest version available. For example, for the model ID azureml://registries/azureml-meta/models/Meta-Llama-3-8B-Instruct/versions/3, copy azureml://registries/azureml-meta/models/Meta-Llama-3-8B-Instruct.

    A screenshot showing a model's details page.

The next section covers the steps for subscribing your workspace to a model offering. You can skip this section and go to Deploy the model to a serverless API endpoint, if you're deploying a Microsoft model.

Subscribe your workspace to the model offering

Serverless API endpoints can deploy both Microsoft and non-Microsoft offered models. For Microsoft models (such as Phi-3 models), you don't need to create an Azure Marketplace subscription and you can deploy them to serverless API endpoints directly to consume their predictions. For non-Microsoft models, you need to create the subscription first. If it's your first time deploying the model in the workspace, you have to subscribe your workspace for the particular model offering from the Azure Marketplace. Each workspace has its own subscription to the particular Azure Marketplace offering of the model, which allows you to control and monitor spending.

Note

Models offered through the Azure Marketplace are available for deployment to serverless API endpoints in specific regions. Check Region availability for models in serverless API endpoints to verify which models and regions are available. If the one you need is not listed, you can deploy to a workspace in a supported region and then consume serverless API endpoints from a different workspace.

  1. Create the model's marketplace subscription. When you create a subscription, you accept the terms and conditions associated with the model offer. Remember you don't need to perform this step for Microsoft offered models (like Phi-3).

    1. On the model's Details page, select Deploy. A Deployment options window opens up, giving you the choice between serverless API deployment and deployment using a managed compute.

      Note

      For models that can be deployed only via serverless API deployment, the serverless API deployment wizard opens up right after you select Deploy from the model's details page.

    2. Select Serverless API with Azure AI Content Safety (preview) to open the serverless API deployment wizard.

    3. Select the checkbox to acknowledge the Microsoft purchase policy.

      A screenshot showing how to deploy a model with the serverless API option.

    4. If you see the note You already have an Azure Marketplace subscription for this workspace, you don't need to create the subscription since you already have one. You can proceed to Deploy the model to a serverless API endpoint.

    5. In the deployment wizard, select the link to Azure Marketplace Terms to learn more about the terms of use. You can also select the Pricing and terms tab to learn about pricing for the selected model.

    6. On the deployment wizard, select the link to Azure Marketplace Terms to learn more about the terms of use. You can also select the Marketplace offer details tab to learn about pricing for the selected model.

    7. Select Subscribe and Deploy.

  2. Once you subscribe the workspace for the particular Azure Marketplace offering, subsequent deployments of the same offering in the same workspace don't require subscribing again.

  3. At any point, you can see the model offers to which your workspace is currently subscribed:

    1. Go to the Azure portal

    2. Navigate to the resource group where the workspace belongs.

    3. On the Type filter, select SaaS.

    4. You see all the offerings to which you're currently subscribed.

    5. Select any resource to see the details.

Deploy the model to a serverless API endpoint

Once you've created a subscription for a non-Microsoft model, you can deploy the associated model to a serverless API endpoint. For Microsoft models (such as Phi-3 models), you don't need to create a subscription.

The serverless API endpoint provides a way to consume models as an API without hosting them on your subscription, while keeping the enterprise security and compliance organizations need. This deployment option doesn't require quota from your subscription.

In this section, you create an endpoint with the name meta-llama3-8b-qwerty.

  1. Create the serverless endpoint

    1. To deploy a Microsoft model that doesn't require subscribing to a model offering, select Deploy and then select Serverless API with Azure AI Content Safety (preview) to open the deployment wizard.

    2. Alternatively, for a non-Microsoft model that requires a model subscription, if you've just subscribed your workspace to the model offer in the previous section, continue to select Deploy. Alternatively, select Continue to deploy (if your deployment wizard had the note You already have an Azure Marketplace subscription for this workspace).

      A screenshot showing a workspace that is already subscribed to the offering.

    3. Give the deployment a name. This name becomes part of the deployment API URL. This URL must be unique in each Azure region.

      A screenshot showing how to specify the name of the deployment you want to create.

      Tip

      The Content filter (preview) option is enabled by default. Leave the default setting for the service to detect harmful content such as hate, self-harm, sexual, and violent content. For more information about content filtering (preview), see Content safety for models deployed via serverless APIs.

    4. Select Deploy. Wait until the deployment is ready and you're redirected to the Deployments page.

  2. At any point, you can see the endpoints deployed to your workspace:

    1. Go to your workspace.

    2. Select Endpoints.

    3. Select the Serverless endpoints tab to display the serverless API endpoints.

  3. The created endpoint uses key authentication for authorization. Use the following steps to get the keys associated with a given endpoint.

    1. To return to the deployment's page, select the endpoint's name from the list of serverless endpoints.
    2. Note the endpoint's Target URI and Key. Use them to call the deployment and generate predictions.

    Note

    When using the Azure portal, serverless API endpoints aren't displayed by default on the resource group. Use the Show hidden types option to display them on the resource group.

  4. At this point, your endpoint is ready to be used.

  5. If you need to consume this deployment from a different workspace, or you plan to use prompt flow to build intelligent applications, you need to create a connection to the serverless API deployment. To learn how to configure an existing serverless API endpoint on a new workspace or hub, see Consume deployed serverless API endpoints from a different workspace or from Prompt flow.

    Tip

    If you're using prompt flow in the same workspace where the deployment was deployed, you still need to create the connection.

Use the serverless API endpoint

Models deployed in Azure Machine Learning and Azure AI studio in Serverless API endpoints support the Azure AI Model Inference API that exposes a common set of capabilities for foundational models and that can be used by developers to consume predictions from a diverse set of models in a uniform and consistent way.

Read more about the capabilities of this API and how you can use it when building applications.

Delete endpoints and subscriptions

You can delete model subscriptions and endpoints. Deleting a model subscription makes any associated endpoint to become Unhealthy and unusable.

To delete a serverless API endpoint:

  1. Go to Azure Machine Learning studio.

  2. Select Endpoints from the left sidebar.

  3. Select the Serverless endpoints tab to display the serverless API endpoints.

  4. Open the endpoint you want to delete.

  5. Select Delete.

To delete the associated model subscription:

  1. Go to the Azure portal

  2. Navigate to the resource group where the workspace belongs.

  3. On the Type filter, select SaaS.

  4. Select the subscription you want to delete.

  5. Select Delete.

Cost and quota considerations for models deployed as serverless API endpoints

Quota is managed per deployment. Each deployment has a rate limit of 200,000 tokens per minute and 1,000 API requests per minute. However, we currently limit one deployment per model per workspace. Contact Microsoft Azure Support if the current rate limits aren't sufficient for your scenarios.

Cost for Microsoft models

You can find the pricing information on the Pricing and terms tab of the deployment wizard when deploying Microsoft models (such as Phi-3 models) as serverless API endpoints.

Cost for non-Microsoft models

Non-Microsoft models deployed as serverless API endpoints are offered through the Azure Marketplace and integrated with Azure AI Studio for use. You can find the Azure Marketplace pricing when deploying or fine-tuning these models.

Each time a workspace subscribes to a given offer from the Azure Marketplace, a new resource is created to track the costs associated with its consumption. The same resource is used to track costs associated with inference and fine-tuning; however, multiple meters are available to track each scenario independently.

For more information on how to track costs, see Monitor costs for models offered through the Azure Marketplace.

A screenshot showing different resources corresponding to different model offers and their associated meters.

Permissions required to subscribe to model offerings

Azure role-based access controls (Azure RBAC) are used to grant access to operations in Azure Machine Learning. To perform the steps in this article, your user account must be assigned the Owner, Contributor, or Azure AI Developer role for the Azure subscription. Alternatively, your account can be assigned a custom role that has the following permissions:

  • On the Azure subscription—to subscribe the workspace to the Azure Marketplace offering, once for each workspace, per offering:

    • Microsoft.MarketplaceOrdering/agreements/offers/plans/read
    • Microsoft.MarketplaceOrdering/agreements/offers/plans/sign/action
    • Microsoft.MarketplaceOrdering/offerTypes/publishers/offers/plans/agreements/read
    • Microsoft.Marketplace/offerTypes/publishers/offers/plans/agreements/read
    • Microsoft.SaaS/register/action
  • On the resource group—to create and use the SaaS resource:

    • Microsoft.SaaS/resources/read
    • Microsoft.SaaS/resources/write
  • On the workspace—to deploy endpoints (the Azure Machine Learning data scientist role contains these permissions already):

    • Microsoft.MachineLearningServices/workspaces/marketplaceModelSubscriptions/*
    • Microsoft.MachineLearningServices/workspaces/serverlessEndpoints/*

For more information on permissions, see Manage access to an Azure Machine Learning workspace.