Let's POWER Automate

From no-code to low-code

Menu
  • Expressions
  • Filters
  • General
  • Application specific solutions
    • Dataverse
    • Excel
    • Forms
    • Outlook
    • Planner
    • Power Apps
    • SharePoint
    • Teams
  • Triggers
  • Ready to use solutions
    • Approval Process Template
    • Task Delegation App
    • The Ultimate Power Automate expressions cheat sheet
    • Power Automate HTTP requests to SharePoint cheat sheet
    • Power Automate HTTP requests to Graph API cheat sheet
  • ABOUT ME
  • Get help with your flow
  • POWER PLATFORM SERVICES
Menu

How to use ChatGPT in your Power Automate flow

Posted on September 24, 2023September 24, 2023 by Tom

“I hear a lot about ChatGPT lately, can I use it to improve my Power Automate flows, to simplify some otherwise complex tasks?”


Given the recent popularity of AI, especially ChatGPT, we can expect that it’ll stay with us. Which is a good thing, if you learn how to use it.

When you build a Power Automate flow, you often process some data. The more complicated the requirement, the more steps/expressions it might take to get the desired result. But what if it wasn’t necessary? If you could just ask AI and get the result you want? And since ChatGPT is the most popular one, how can you use it in your flow?

Note: this solution is using the generic HTTP request action, therefore, you need Power Automate premium license. There’re also some costs associated with using ChatGPT.

Get an authentication token

Before you can communicate with ChatGPT, you must create an account. Go the OpenAI site and ‘Get started’.

Create a new account or select an existing one to continue. Since you want to call ChatGPT from a flow, go to the API section.

The AI needs to know that you’re accessing it, that you’re a valid, registered user – that’s why you’ll need your personal token. Go to API keys and create a new secret key. That’s a key you’ll need for the flow.

use ChatGPT Power Automate

Use it in a flow

Once you have the key, you can start sending HTTP requests to ChatGPT. Use the latest endpoint as the URI, at the time of this article it’s as below:

Method: POST

URI: 
https://api.openai.com/v1/chat/completions

Headers:
{
  "Content-Type": "application/json",
  "Authorization": "Bearer <secretKeyFromAbove>"
}

The request body needs only 2 parameters. The first one is which model you want to use. There’re two models available at this endpoint: gpt-4 and gpt-3.5-turbo. Try to use gpt-3.5-turbo as it’s more cost efficient and will handle most of your requests. If it doesn’t give you the desired results, you can always switch to gpt-4 later.

The second parameter is the message, your question/request towards the AI. Since you want to interact directly as a user, not telling the AI to reply in a specific manner, use the role ‘user’, e.g.

{
  "model": "gpt-3.5-turbo",
  "messages": [
    {
      "role": "user",
      "content": "Tell me something about Tom Riha and his Power Automate experience"
    }
  ]
}
use ChatGPT Power Automate

Wait until it finishes and extract the response from the HTTP request output with an expression.

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

Use it to do more complex tasks in a flow

Until now it was just a simple question – answer communication. What about the more complex data processing mentioned at the beginning of the article?

When you’re communicating with ChatGPT, you can send not only the questions, but also the data with some instructions. You can send it an email content and tell it what you’d like to extract from it, or data from a file, as in the next example.

In the past I wrote an article on processing Teams attendance report to get the participants and how long they attended the meeting. It’s quite a complex solution using a lots of data operations – extract specific rows/columns, convert time, etc.

Now you can ask ChatGPT to do all the data processing with a single request.

Describe the request, add the content of the file, and send in the same HTTP request.

Note: my Teams attendance report is in Czech language, but I hope you can understand the request anyway.

use ChatGPT Power Automate

There’s just one difference when extracting the data here. I asked for an array of JSON objects, hence I must convert the output to JSON to clean it.

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

Summary

As you can see, it’s quite easy to use ChatGPT in a Power Automate flow. It’s not for free as you need Power Automate premium license and the interaction with ChatGPT will also cost you a few cents, but as a result you can build much simpler flows that can automate a lot more of your daily tasks.


πŸš€ Master Power Automate

Join 2,000+ professionals getting actionable Power Automate tutorials, solutions, cheat sheets & tips every week.

No spam. Unsubscribe anytime.

1 thought on “How to use ChatGPT in your Power Automate flow”

  1. Ben Leal says:
    January 17, 2025 at 4:12 pm

    Two things. I tried to sign up for your newsletter but was prompted to select a list, however none are presented. Just name and email address fields are present.

    Secondly, would you revise to show the use of dynamic content with updated screenshots? I’m attempting to build a flow that feeds newly received emails to chatgpt for it to draft responses. Therefore, I need to pass the “body” value from Outlook but am not having success with your method.

    Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

πŸš€ Master Power Automate

Join 2,000+ professionals getting actionable Power Automate tutorials, solutions, cheat sheets & tips every week.

No spam. Unsubscribe anytime.

Still exchanging emails to get things approved?

Use the Approval Process Template and the Task Delegation App to skip the hard part and deploy an automated, fully functional approval solution on a SharePoint list in minutes! And then the next one, and the next one...

Approval Template Preview ✨ Learn more ✨

Turn ideas into flows with ease!

Grab the complete Power Automate Cheat Sheet Bundleβ€”everything you need to master expressions, SharePoint HTTP calls, and Graph API in Power Automate.

Cheat Sheet Bundle Preview ✨ Get the Cheat Sheets

Didn't find what you were looking for?
Need to adjust a solution to fit your needs?
Or would you just like to get an assistance from somebody with thousands of hours of experience with Power Automate?

Power Automate blogs worth visiting

Damien Bird
Dennis (Expiscornovus)
Paul Murana

©2025 Let's POWER Automate | Theme by SuperbThemes