#PowerAutomate – Using OpenAI APIs, like ChatGPT, Dall-E and more. Also in Azure!
Tags: englishpost, dalle, openai
Published: 2023-04-04 15:38:51

---
title: #PowerAutomate – Using OpenAI APIs, like ChatGPT, Dall-E and more. Also in Azure!
published: true
date: 2023-04-03 14:15:40 UTC
tags: EnglishPost,DallE,EnglishPost,OpenAI
canonical_url: 
---

Hi!

Back in March we hosted 3 sessions, and we showed how to use OpenAI models and features in Power Apps, Power Automate and Power Virtual Agents. You can check the recordings here: [https://aka.ms/OpenAIPowerPlatformSeries](https://aka.ms/OpenAIPowerPlatformSeries)

These AI models are available in several places, like OpenAI APIs and Azure OpenAI Services.

#### Scenario

Let’s learn how to use one of these models in a Power Automate Flow using an HTTP Request Action and processing the JSON Response.

For this 1st demo, we’ll use:

- [OpenAI APIs](https://platform.openai.com/docs/guides/images) 
- [Image Generation Scenario](https://platform.openai.com/docs/guides/images)

In the official documentation we can learn the specific format that we need to use to send a POST HTTP Request to the service. In example

```

{
  "prompt": "A cute puppy playing soccer in the moon, looking at the camera, cartoon style",
  "n": 1,
  "size": "512x512"
}

```

And the main parameters are

- prompt: the prompt to generate the image.
- n: the numbers of images to be generated.
- size: the size of the generated image.

Super easy! Now let’s add this into a Power Automate flow. I do this in three steps. Like this:

![3 actions in a flow to make the http requesto to the image generator api. The 3 steps are: HTTP REQUIEST, Parse JSON and Parse JSON.](https://brunocapuano.files.wordpress.com/2023/04/image.png?w=1024)

Let’s take a look at some specifics for each action.

#### HTTP Request

![](https://brunocapuano.files.wordpress.com/2023/04/image-1.png?w=1024)

- Method: POST.
- We use the API endpoint for the Image Generation.
- In Headers we define Content-Type as application/json.
- In the Body, I use the previous JSON demo, and replace the prompt with a flow variable.
- Authentication is BASIC.
- Username is a space character (is required)
- Password is the OpenAI Key. 

#### Parse JSON from the HTTP Request

Now it’s time to parse the body output from the previous step.

![](https://brunocapuano.files.wordpress.com/2023/04/image-2.png?w=1024)

I use this sample JSON response to generate the schema.

```

{
  "created": 123456,
  "data": [
    {
      "url": "https://imageurl"
    }
  ]
}

```

#### Parse JSON to get the final result

Now it’s time to a 2nd JSON Parse. The previous response contains a collection of generated images in DATA. And even if we only requested one, we need to parse this collection.

We can use the first() function to get the first element of the response, and then parse the JSON to get the final results.

![](https://brunocapuano.files.wordpress.com/2023/04/image-3.png?w=1024)

I use this sample JSON to generate the Schema.

```

    {
      "url": "https://imageurl"
    }

```

And that’s it, after these three steps we can get an url to a generated image. And we can use it in our Power Automate Flows!

In the next post, I’ll show a similar scenario using Azure OpenAI Services.

Happy coding!

Greetings

El Bruno

More posts in my blog [ElBruno.com](https://www.elbruno.com).

More info in [https://beacons.ai/elbruno](https://beacons.ai/elbruno)

* * *