Learn how to deploy Semantic Kernel to Azure as a web app service

In this how-to guide we will provide steps to deploy Semantic Kernel to Azure as a web app service. Deploying Semantic Kernel as web service to Azure provides a great pathway for developers to take advantage of Azure compute and other services such as Azure Cognitive Services for responsible AI and vectorized databases.
You can use one of the deployment options to deploy based on your use case and preference.
Considerations
Azure currently limits the number of Azure OpenAI resources per region per subscription to 3. Azure OpenAI is not available in every region. (Refer to this availability map) Bearing this in mind, you might want to use the same Azure OpenAI instance for multiple deployments of Semantic Kernel to Azure.
F1 and D1 App Service SKU's (the Free and Shared ones) are not supported for this deployment.
Ensure you have sufficient permissions to create resources in the target subscription.
Using web frontends to access your deployment: make sure to include your frontend's URL as an allowed origin in your deployment's CORS settings. Otherwise, web browsers will refuse to let JavaScript make calls to your deployment.
| Use Case | Deployment Option |
|---|---|
| Use existing: Azure OpenAI Resources Use this option to use an existing Azure OpenAI instance and connect the Semantic Kernel web API to it. |
PowerShell File Bash File |
| Create new: Azure OpenAI Resources Use this option to deploy Semantic Kernel in a web app service and have it use a new instance of Azure OpenAI. Note: access to new Azure OpenAI resources is currently limited due to high demand. |
PowerShell File Bash File |
| Use existing: OpenAI Resources Use this option to use your OpenAI account and connect the Semantic Kernel web API to it. |
PowerShell File Bash File |
Script Parameters
Below are examples on how to run the PowerShell and bash scripts. Refer to each of the script files for the complete list of available parameters and usage.
PowerShell
- Creating new Azure OpenAI Resources
.\DeploySK.ps1 -DeploymentName YOUR_DEPLOYMENT_NAME -Subscription YOUR_SUBSCRIPTION_ID
- Using existing Azure OpenAI Resources
After entering the command below, you will be prompted to enter your Azure OpenAI API key. (You can also pass in the API key using the -ApiKey parameter)
.\DeploySK-Existing-AzureOpenAI.ps1 -DeploymentName YOUR_DEPLOYMENT_NAME -Subscription YOUR_SUBSCRIPTION_ID -Endpoint "YOUR_AZURE_OPENAI_ENDPOINT"
- Using existing OpenAI Resources
After entering the command below, you will be prompted to enter your OpenAI API key. (You can also pass in the API key using the -ApiKey parameter)
.\DeploySK-Existing-OpenAI.ps1 -DeploymentName YOUR_DEPLOYMENT_NAME -Subscription YOUR_SUBSCRIPTION_ID
Bash
- Creating new Azure OpenAI Resources
./DeploySK.sh -d DEPLOYMENT_NAME -s SUBSCRIPTION_ID
- Using existing Azure OpenAI Resources
./DeploySK-Existing-AzureOpenAI.sh -d YOUR_DEPLOYMENT_NAME -s YOUR_SUBSCRIPTION_ID -e YOUR_AZURE_OPENAI_ENDPOINT -o YOUR_AZURE_OPENAI_API_KEY
- Using existing OpenAI Resources
./DeploySK-Existing-AI.sh -d YOUR_DEPLOYMENT_NAME -s YOUR_SUBSCRIPTION_ID -o YOUR_OPENAI_API_KEY
Azure Portal Template
If you choose to use Azure Portal as your deployment method, you will need to review and update the template form to create the resources. Below is a list of items you will need to review and update.
- Subscription: decide which Azure subscription you want to use. This will house the resource group for the Semantic Kernel web application.
- Resource Group: the resource group in which your deployment will go. Creating a new resource group helps isolate resources, especially if you are still in active development.
- Region: select the geo-region for deployment. Note: Azure OpenAI is not available in all regions and is currently to three instances per region per subscription.
- Name: used to identify the app. App Service SKU: select the pricing tier based on your usage. Click here to learn more about Azure App Service plans.
- Package URI: there is no need to change this unless you want to deploy a customized version of Semantic Kernel. (See this page for more information on publishing your own version of the Semantic Kernel web app service)
- Completion, Embedding and Planner Models: these are by default using the appropriate models based on the current use case - that is Azure OpenAI or OpenAI. You can update these based on your needs.
- Endpoint: this is only applicable if using Azure OpenAI and is the Azure OpenAI endpoint to use.
- API Key: enter the API key for the instance of Azure OpenAI or OpenAI to use.
- Semantic Kernel API Key: the default value of "[newGuid()]" in this field will create an API key to protect you Semantic Kernel endpoint. You can change this by providing your own API key. If you do not want to use API authorization, you can make this field blank.
- CosmosDB: whether to deploy a CosmosDB resource to store chats. Otherwise, volatile memory will be used.
- Qdrant: whether to deploy a Qdrant database to store embeddings. Otherwise, volatile memory will be used.
- Speech Services: whether to deploy an instance of the Azure Speech service to provide speech-to-text for input.
What resources are deployed?
Below is a list of the key resources created within the resource group when you deploy Semantic Kernel to Azure as a web app service.
- Azure web app service: hosts Semantic Kernel
- Application Insights: application logs and debugging
- Azure Cosmos DB: used for chat storage (optional)
- Qdrant vector database (within a container): used for embeddings storage (optional)
- Azure Speech service: used for speech-to-text (optional)
Verifying the deployment
To make sure your web app service is running, go to https://YOUR_INSTANCE_NAME.azurewebsites.net/healthz
To get your instance's URL, go to your deployment's resource group (by clicking on the "Go to resource group" button seen at the conclusion of your deployment if you use the "Deploy to Azure" button). Then click on the resource whose name ends with "-skweb".
This will bring you to the Overview page on your web service. Your instance's URL is the value that appears next to the "Default domain" field.
Changing your configuration, monitoring your deployment and troubleshooting
After your deployment is complete, you can change your configuration in the Azure Portal by clicking on the "Configuration" item in the "Settings" section of the left pane found in the Semantic Kernel web app service page.
Scrolling down in that same pane to the "Monitoring" section gives you access to a multitude of ways to monitor your deployment.
In addition to this, the "Diagnose and solve problems" item near the top of the pane can yield crucial insight into some problems your deployment may be experiencing.
If the service itself is functioning properly but you keep getting errors (perhaps reported as 400 HTTP errors) when making calls to the Semantic Kernel, check that you have correctly entered the values for the following settings:
- AIService:AzureOpenAI
- AIService:Endpoint
- AIService:Models:Completion
- AIService:Models:Embedding
- AIService:Models:Planner
AIService:Endpoint is ignored for OpenAI instances from openai.com but MUST be properly populated when using Azure OpenAI instances.
How to clean up resources
When you want to clean up the resources from this deployment, use the Azure portal or run the following Azure CLI command:
az group delete --name YOUR_RESOURCE_GROUP
Take the next step
Learn how to make changes to your Semantic Kernel web app, such as adding new skills.
If you have not already done so, please star the GitHub repo and join the Semantic Kernel community! Star the Semantic Kernel repo
