Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
ALERT: The support homepage carousel is not displaying. We are working toward a resolution.

Creating a REST API Connection for Snowflake Cortex Agent

cancel
Showing results for 
Search instead for 
Did you mean: 
Dalton_Ruer
Support
Support

Creating a REST API Connection for Snowflake Cortex Agent

Last Update:

Dec 30, 2025 3:18:42 PM

Updated By:

Dalton_Ruer

Created date:

Dec 30, 2025 3:14:40 PM

In a previous post called Calling Snowflake's Cortex Agent API, I started the post by saying the focus of the post was about how the REST API worked not how to create the connection to it. This post is focused solely on how to create a REST API connector for Snowflake Cortex Agents. 

Snowflake Agents

Snowflake allows you to build "agents." While I have built several, this post is going to focus on one that I called "SynthAgent." 

Dalton_Ruer_2-1767103275606.png

They also provide a way you for you to question them directly in their user interface. I can simply ask a question like "Who are the top 10 admitting providers?" and voila ... I get an answer:

Dalton_Ruer_1-1767103121649.png

 

Actually as my previous post indicated, when you talk to an agent you actually get to see it's entire stream of thought. 

Dalton_Ruer_3-1767103587242.png

Snowflake Cortex Agent API

While asking an isolated question inside of Snowflake is certainly handy-dandy, the bigger picture is in the fact that in the world we live in, agents should play nice with others. So, Snowflake created an API that allows others outside of the Snowflake user interface to speak with t...

Dalton_Ruer_4-1767103844098.png

Obviously you will need to use your own server and your own agents, but to help you understand the URL I wanted to show you the URL I will use in this post for this Cortex Agent API. Refer to the first image to see the database/schema/agent:

https://AYFR...mputing.com/api/v2/databases/SNOWFLAKE_INTELLIGENCE/schemas/AGENTS/agents/SYNTHAGENT:run

Creating your REST API Connector

While it's a rather complicated URL path, it is in fact nothing more than a URL path. Which is the most important thing that the Qlik Rest API Connector needs. Begin by creating a new connection. Be sure and choose the correct space where you want this new connector created and simply choose "REST". 

Dalton_Ruer_5-1767104602549.png

 

Paste in the correct URL and choose the POST method:

Dalton_Ruer_6-1767104703413.png

After choosing POST as the method, the connector is going to prompt you for the BODY of the call. 

Dalton_Ruer_8-1767104888132.png

My agent is built from a Snowflake Semantic View. Based on that, here is the sample body that I passed to my SYNTHAGENT URL: 

{
"messages": [
{
"role": "user",
"content": [
{
"type": "text",
"text": "Who are the top 10 admitting providers?"
}
]
}
],
"tool_choice": {
"type": "auto"
}
}

Notice that I'm asking the exact same question that I asked directly in Snowflake so that I can test the results I get back to ensure it is working. 

Additional request parameters

Based on the Snowflake Cortex Agent API documentation, you will need to configure a parameter and a few headers that are passed when calling the URL. 

Query parameters

You need to have a parameter named Response-Type with the value text/event-stream

Dalton_Ruer_0-1767120954761.png

Query Headers 

You need to create 4 Query Headers.

Authorization - This is to define the security for the API call. Snowflake provides multiple types of security. In this example I'm using a token model. To create your API Token, called Programmatic access token (PAT) in Snowflake you simply go to your profile, go to Settings and choose Authentication. Then Generate new token. 

Dalton_Ruer_2-1767121490859.png

 

When you create the PAT, simply copy the value and in the value field type Bearer and then paste in your PAT. 

User-Agent use QlikSense.

Accept simply use */*

Content-Type use application/json

Dalton_Ruer_3-1767121519854.png

Checking the box that isn't there

You had to hard code your question in the body, but in the real world in which you live are you always going to make all users, always see answers for just that question?"

This is when you need to reply out loud in your biggest voice "OF COURSE NOT!!!!"

Then I would say "So check that box that says Enable Dynamic Parameters" or any of the alternatives shown:

Dalton_Ruer_4-1767121643025.png

Because any of those check boxes would make total sense to you "Oh I need to check the box that allows me to change the question based on what my user asks." 

Instead I need you check the box that only makes sense, after you know what it does. It's the check box that says Allow "WITH CONNECTION"

Dalton_Ruer_5-1767121953174.png

It will make sense in a few minutes why the button has that name. For now just now it relates to any of the 3 button names I wish it had. 😁

Test your connection

Finally give your connection a name and press the Test connection button. 

Dalton_Ruer_7-1767122178583.png

 

If all of your security is configured correctly in Snowflake (Click here to see all of the things you need to ensure in Snowflake itself.) then you will get a Connection succeeded result. 

Dalton_Ruer_6-1767122116899.png

If you see an error like "Unsupported Accept header null is specified. It simply means that you followed instructions from some other post and left out the Accept */* that I showed above an retest the connection. 

Dalton_Ruer_9-1767122429420.png

Once you see the Connection succeeded save your connection so that we can actually make the call to the agent and see how the results look. 

Calling the Connector

Congratulations you know have a connector in place to call your Snowflake Cortex Agent REST API. Woohoo. 😎

Click the Select data button for the connector

Dalton_Ruer_10-1767122662834.png

It will default to CSV for the response type which is perfect. 

The Delimiter should be Tab

Check the box for CSV Has header.

Check the CSV_source box. 

Once you check that box it will go and make the call. If you see results like below you know that have in fact successfully asked your Snowflake Cortex Agent that question that was hard coded. 

Dalton_Ruer_11-1767122870405.png

Press the Insert script button to actually insert the script block into your load script. Isn't this great I can reload my application and get answers to the same question over and over and over again. We are really living large. Right?

Dalton_Ruer_12-1767123072167.png

Our connector is working great, but I'm still hung up on that whole "same question over and over and over again thing." Logically what we would like to do, and more importantly can do ... is call the REST API and give it the question on the fly. In other words we would need to give it the BODY for the the call on the fly ... like this:

Dalton_Ruer_0-1767123655396.png

WITH CONNECTION

WITH CONNECTION is the syntax key word that is added to calls to REST API Connectors. Now I get why that checkbox that didn't make sense is called Allow WITH CONNECTION. It is letting you declare when you create the connection if the developers with access to the connection are allowed to do that or not. Glad they didn't rename them with any of the names I suggested. We would have a nightmare on our hands. 

Now I have the ability to create a variable with the body, that has whatever question I want in it:

Let vBody = '{
  "messages": [
    {
      "role": "user",
      "content": [
        {
          "type": "text",
          "text": "Totally different question for you to answer for me now. Now I need to know only the top 3 Attending Physicians"
        }
      ]
    }
  ],
  "tool_choice": {
    "type": "auto"
  }
}';
 
Let vRequestBody = Replace('$(vBody)', '"', chr(34)&chr(34));
 
RestConnectorMasterTable:
Replace Load *;
SQL SELECT 
"event: response.status"
FROM CSV (header on, delimiter "tab", quote """") "CSV_source"
WITH CONNECTION(
BODY "$(vRequestBody)"
);
 
[CSV_source]:
LOAD [event: response.status]
RESIDENT RestConnectorMasterTable;
 
DROP TABLE RestConnectorMasterTable;
 
I can make the Body/Question even more variable if I desire. Which of course you will want to do because you want the end user to ask the question and then have this code run:
Dalton_Ruer_2-1767125321575.png

 

Results

When you look at the results you will realize that the Snowflake Cortex Agent API does not just return the answer to our question. It returns an entire event stream. Which is precisely why when we set the Response-Type parameter initially, we needed to set it to text/event-stream. 

Dalton_Ruer_3-1767125461688.png

 

Great news is you have successfully created your REST API connector so you can talk to the Snowflake Cortex Agent. The next step is to check out my previous post where I walk you through how to process the results. https://community.qlik.com/t5/Member-Articles/Calling-Snowflake-s-Cortex-Agent-API/ta-p/2535284

PS - This post was planned for a later date. Be sure to thank @chriscammers for requesting it sooner. 😃 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Labels (1)
Contributors
Version history
Last update:
yesterday
Updated by: