Using Managed Identity and Logic Apps to Trigger Azure OpenAI
Date published:
How to Use Logic Apps with Azure OpenAI and Managed Identity
Azure Logic Apps is a cloud-based service that allows you to create workflows that integrate with various services and systems. One of the services that Logic Apps can integrate with is Azure OpenAI, which provides natural language processing capabilities. In this tutorial, we’ll show you how to use Logic Apps with Azure OpenAI and Managed Identity.
The first step is to create a managed identity for your logic app. A managed identity is a feature of Azure Active Directory that allows you to authenticate your Logic App with other Azure services without having to manage credentials.
To create a user-managed identity for your Logic app, follow these steps:
- Go to the Azure portal and navigate to your Logic app.
- Click on the “Identity” tab in the left-hand menu.
- Click on the “User assigned” tab and click on the “+ Add” button.
- In the “Add user-assigned managed identity” blade, enter a name for the managed identity and click “Create.”.
- Once the managed identity is created, copy the object ID for the identity.
Using Managed Identity with Logic Apps and Azure OpenAI
Once you have a managed identity, you can use it in a logic app to authenticate with Azure OpenAI. Here’s an example of a Logic App definition that uses Managed Identity to send a POST request to Azure OpenAI:
Create a recurrence trigger that runs every 5 minutes.
Add an HTTP action that sends a POST request to the Azure OpenAI service.
In this example, the Logic App sends a POST request to the Azure OpenAI service every 5 minutes. The request body contains instructions for the OpenAI model to generate a response based on the provided messages. The messages instruct the model to behave as an AI recipe maker that creates keto recipes, and then ask it to create a random recipe and inquire about the weather.
On the authentication tab, select “Managed Identity” as the authentication type and enter the Object ID of the Managed Identity you created earlier. For the identity field, type “https://cognitiveservices.azure.com” as it will query the Azure OpenAI service.
Parse the JSON response from the Azure OpenAI service and extract the generated text. In the content, just select the body from the dynamic content, and in the body, you can use the below schema.
Assign Permission
Navigate to your Azure OpenAI and assign the managed identity you created earlier to the resource. I would recommend giving it Cognitive Services OpenAI User permission, as it should have the least privilege access.
Test the Logic App Workflow
Now that you’ve created the Logic App workflow, you can test it to make sure it’s working correctly.
To test the Logic App workflow, follow these steps:
Go to the logic apps you created and run the trigger manually. However, you can also wait for the trigger to run automatically. Once the trigger runs, go to Azure OpenAI, and on the system prompt, enter ‘You are an AI recipe maker that makes keto recipes, and on the completion prompt, enter ‘Create a random recipe’." The Logic App should send a POST request to the Azure OpenAI service and receive a response. The response should contain the generated text from the Azure OpenAI service.
Conclusion
In this tutorial, we showed you how to use Logic Apps with Azure OpenAI and Managed Identity. By following these steps, you can create a Logic App workflow that integrates with Azure OpenAI and uses Managed Identity for authentication. This allows you to securely and easily integrate natural language processing capabilities into your workflows. It also allows you to customise the prompt in the Logic App to generate different responses.
I hope you enjoyed this blog post, and if you have any questions, feel free to contact me on social media.