AIAdvanced

Calling Azure OpenAI from Power Automate

Call your own Azure OpenAI deployment from a cloud flow with the HTTP action, keep the key out of your flow, and parse the response properly.

Prerequisites

  • An Azure subscription with an Azure OpenAI resource and a model deployment
  • Power Automate premium licence (the HTTP action is premium)

What you'll learn

  • Know when to use Azure OpenAI instead of AI Builder
  • Build the chat completions request in an HTTP action
  • Store the key safely with an environment variable or Key Vault
  • Extract the answer from the response
On this page
  1. AI Builder or Azure OpenAI?
  2. What you need from Azure
  3. Keep the key out of the flow
  4. Build the request
  5. Read the answer
  6. Handle failures

AI Builder prompts are the easiest route to GPT in Power Platform. Sometimes, though, you need your own Azure OpenAI deployment — to pick a specific model, keep data in your own Azure region, or share one deployment across apps. Here's how to call it from a flow.

AI Builder or Azure OpenAI?

NeedAI Builder promptAzure OpenAI
Fastest to buildYesNo
No Azure subscription neededYesNo
Choose exact model and versionLimitedYes
BillingAI Builder creditsAzure usage
Reuse from non-Power Platform appsNoYes

What you need from Azure

From your Azure OpenAI resource, note three values: the endpoint (for example https://my-resource.openai.azure.com), the deployment name you gave the model, and an API key. You also need the API version your resource supports — check the Azure OpenAI documentation for the current one.

Keep the key out of the flow

Never paste the key into the HTTP action. Two good options:

  • Environment variable of type Secret, backed by Azure Key Vault — the cleanest choice for solutions that move between environments.
  • At minimum, a Secret environment variable so the key isn't visible in the flow definition.

Build the request

Add an HTTP action:

  • Method: POST
  • URI: https://my-resource.openai.azure.com/openai/deployments/{deployment}/chat/completions?api-version={version}
  • Headers: Content-Type: application/json and api-key: <your secret variable>
  • Body:
JSON
{
  "messages": [
    { "role": "system", "content": "You summarise Dataverse case notes for managers in 3 bullet points." },
    { "role": "user", "content": "@{triggerBody()?['notes']}" }
  ],
  "temperature": 0.2,
  "max_tokens": 300
}

Read the answer

The model's reply is inside the first choice. Use this expression in a Compose action:

JavaScript
body('HTTP')?['choices']?[0]?['message']?['content']

Also log body('HTTP')?['usage']?['total_tokens'] so you can track cost per run.

Handle failures

Wrap the HTTP call in a Try scope. In the Catch scope, check the status code:

  • 429 means you hit a rate limit — retry later with a delay.
  • 400 often means the content was filtered or the body is malformed.
  • 401 means the key is wrong or expired.
J / K next or previous article

Jagadeesan P

Found this useful? I share new guides on LinkedIn.

Follow