Yesterday I looked at how to use the Azure AI Foundry connector in Power Automate. Today I’m doing the same within Power Apps, creating a Q&A app using GPT 4.1.

The Q&A app

So the app that I want to create needs to look like this

A Q&A Power App using the Azure AI Foundry connector
A Q&A Power App using the Azure AI Foundry connector

Now you could of course call the flow that we created yesterday from the app and then call this flow every time the user asks a question run the flow. But I’m going to take this a step further.

Calling the Azure AI Foundry connector from a Power App

First of all we need to add an input box, a Rich text editor and a button to the screen in the app.

Then we need to add the Azure AI Foundry connection. Make sure that you select the Azure AI Foundry Inference connector. The Azure AI Foundry Agent Service is a new connector that was released today. But that is going to be a different post soon.

Adding the Azure AI Foundry connector to the app
Adding the Azure AI Foundry connector to the app

Then the magic all happens within the button’s OnSelect code.

Set(myVar, ParseJSON("{""myValue"" : ""Return in HTML format remove html header, " & TextInput2.Text & """}"));

Set(varOutput, AzureAIFoundryInference.ChatCompletion( {'api-version': "2025-01-01-preview",
                                          max_tokens:(1000),
                                          model:("gpt-4.1"),
                                          temperature:(1),
                                          top_p:(1), 
                                          messages:([{role:"user",content: myVar.myValue}])
                                        }
                                    )
)

Now you might ask why set a variable using the ParseJSON function, can we not just use the code directly in the messages property? The challenge here is that the content in the messages property has to be untyped. Using the Parse JSONM we can very quickly create untyped data.

Formatting the output as HTML

Then within my prompt you will notice that we’re adding “Return in HTML format remove html header,” to the actual question entered by the user.

This will ensure that we get HTML returned rather than the default Markdown language. This is to make sure that our app will display formatted text properly.


Discover more from SharePains

Subscribe to get the latest posts sent to your email.

Related Posts

11 thoughts on “How to use the Azure AI Foundry connector in Power Apps

  1. The connection works for me when I’m in development mode in the PowerApps application. When I launch the app from my phone or from the browser, I get the error 404 – Resource not found.

    1. It sounds like access to the end point has been restricted from your phone. You might want to check the access restrictions on the AI Foundry endpoint.

  2. Hello, i get this error
    Incompatible type. The ‘messages.content’ column in the data source you’re updating expects a ‘Table’ type and you’re using a ‘Dynamic’ type.

    And when running:
    AzureAIFoundryInference.ChatCompletion({
    ‘api-version’: (“2024-08-01-preview”),
    model: (“gpt-4.1-mini”),
    messages: (Table({
    role: “user”,
    content: {
    Value: ParseJSON(
    JSON(
    Table({
    Type: “text”,
    Text: “aaa”
    })
    )
    )
    }
    })),
    max_tokens: (500), temperature:(1)
    })

    i get
    AzureAIFoundryInference.ChatCompletion failed: {
    “error”: {
    “message”: “Missing required parameter: ‘messages[0].content[0].type’.”,
    “type”: “invalid_request_error”,
    “param”: “messages[0].content[0].type”,
    “code”: “missing_required_parameter”
    }
    }

    Could you please help me, Pieter?

    1. Hi Brandon,

      I had a quick look into this. My app that I created originally still works. However when I created a new app and copied all the controls across the app did not work. So my code was identical and the error the same as yours.

      It looks like there is something broken in this connector, however strangely enough my original app is still the same as before. This might require a support call with Microsoft. Please feel free to open a chat and we can discuss this further.

      1. Hey Pieter,
        Yeah, i think i got you on LinkedIn, so we can keep in touch there, thanks!

      2. Hi both,

        Did you find a solution to the above problem? I am facing the same issue

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.