Snowflake Cortex Completion API + LaunchDarkly SDK Integration
Snowflake Cortex Completion API + LaunchDarkly SDK Integration
Snowflake Cortex Completion API + LaunchDarkly SDK Integration
Published August 21st, 2025
This tutorial walks through an integration between the Snowflake Cortex Completion API and LaunchDarkly’s AI SDKs. We’ll be using a Snowflake Personal Access Token to query the Cortex API and receive completion responses.
Leveraging Snowflake’s gateway approach to completions alongside LaunchDarkly’s ability to make runtime changes to AgentControl, you can update the models, prompts, and parameters that you’re using in the Snowflake endpoints in real-time.
This tutorial is presented in TypeScript, but since we’re using Snowflake’s REST API it’s universal to any language in which you can access Snowflake. Snowflake additionally has a Python package that can be used to access their AI and ML functions.
If you are new to Snowflake, there is some setup you’ll need to do to get an application running, like setting up a user that is able to access the API.
Head into your Snowflake instance and follow the guide provided by Snowflake for authenticating against the REST API, and the guide for authenticating against the Cortex REST API.
Pay attention to:
SNOWFLAKE.CORTEX_USER database role if it’s not already presentAdmin Privileges Required for Network Policies
You need admin privileges to create Network Policies for Personal Access Token authentication. If you don’t have admin access:
Before we write any code, we’ll go into LaunchDarkly and create a config to be used in the integration.
Navigate to your LaunchDarkly instance and follow these steps:


claude-3-5-sonnetMake sure that the region you’re accessing from has support for the model you select. You can view model availability on this page.


{{variables}} signify a variable that will be replaced at the time you retrieve your config. This is how you provide dynamic content to your Configs such as contextual user information


disabled variation which is used to signal that a config is turned off. We’ll revisit this aspect later in the code.

You’ve now targeted a variation which can be served in the SDK. We’ll come back to this later once we’ve got some code set up. For now, just copy the key in your sidebar for later:

Next, we’ll set up our sample application so that we can see AgentControl and the Snowflake REST API interacting in real-time. This section assumes some knowledge with TypeScript and the NodeJS ecosystem, but can be accomplished in any language with AI SDK support.
For the following sections, these are instructions to set it up as a new application. If you’re not concerned about which piece does what or having a clean slate, you can also just clone this repository and run npm install and then npm run start after filling out the .env section.
Follow the ExpressJS installation guide to set up a new project leveraging Express.
Let’s create some of the structure we’ll need for the app:
.envThe last command created a .env file that we’ll use to register our secrets so they can be securely loaded by the application.
Within this file, fill out the following values:
The Snowflake account identifier and Personal Access Token should be available from following the authentication instructions for Snowflake.
If you do not know how to get an active LaunchDarkly SDK key, you can follow this guide.
package.jsonGrab the contents of the package.json file from the repository and replace your local package.json file.
Now run npm install to install our dependencies. Once that finishes, run typescript --init from the project folder to create a tsconfig.json file. You’ll need the dependencies in here to process TypeScript files and run your local application.
The dependencies in this file do the following:
@types/express, typescript)nodemon, ts-node, dotenv)@launchdarkly/node-server-sdk, @launchdarkly/server-sdk-ai)We are using default TypeScript settings. Feel free to edit these to match your project’s needs.
index.tsThe index.ts file is responsible for initializing the application. We’ll be including two routes; one to render an HTML page and one to respond to the completion.
Grab the index.ts file from the repo and replace this content. The file has comments explaining the functionality.
index.htmlReplace the index.html file in views/index.html with the same content from the repository, or use it as a guideline to build your own interface for the chat. This file is also commented, but outside of the HTML structure, you’ll want to pay attention to the <script> at the bottom of the page which handles making the API call.
Now that we have an application, we can start wiring up LaunchDarkly to the Snowflake API.
We’ll set up the LaunchDarkly clients in app/launchdarklyClient.ts:
The LaunchDarkly AI SDK allows you to use the features of AgentControl within the LaunchDarkly SDK.
Within app/completions.ts let’s go ahead and set up the Snowflake call:
Navigate to your root directory and run npm run start to start the application.
When you navigate to localhost:3000 (or whichever port you changed it to) you should see a simple screen that looks like this:

Enter a query into the textarea, such as “How do I create a user in Snowflake?” and after a few moments a response will be generated:

We can see in the response that it lists the model we’re using to generate the completion.
Now that we have a completion endpoint set up, let’s create a new variation and change the model at runtime. You can minimize your code editor for now; we’ll only need to make changes in the LaunchDarkly UI!
llama3.1-8b and edit the system message slightly for tone:

Now, let’s head back over to our app on the localhost URL. Without refreshing the page or restarting the server, go ahead and re-submit the request.
Our output was now generated by our llama3.1-8b model rather than the Sonnet model we were leveraging earlier:

And that’s it! We’ve now made a runtime model change on an active config.
We didn’t have to change any code to change the model, and there’s more we can tweak such as the model’s parameters and messages. We can add messages and have them automatically inserted at runtime, test different models on different customers, and tweak parameters in a live system to see how the models respond in real-world conditions.
The last point we’ll touch on is how we can optionally capture data about our config invocations and send those over to LaunchDarkly.
To set up monitoring, we need to extract the tracker object from our config and call some track methods that will communicate the metrics to LaunchDarkly.
Let’s update the app/completions.ts file to include tracking:
We now capture a duration by setting a timer before and after the call, and use the usage parameter returned from Snowflake to capture the token usage. These metrics will appear in your dashboard for your config under the “Monitoring” tab:

You’ll receive additional information on this page about when different variations released and when changes were made to the configs so that you can keep track of what changes have what impact on your completions.
This is a simple example but demonstrates how you can use the power of Snowflake’s Cortex completion gateway in conjunction with AgentControl. Together, they allow you to tweak models in real-time by selecting any models available in your region and having them update seamlessly without requiring any code changes.
Additionally, with the power of LaunchDarkly’s targeting you can serve different models and prompts to different users, and even run experiments against your AgentControl to see which model and prompts best fit your features.
To Get started with AgentControl, sign up for a free trial. You can also contact us at aiproduct@launchdarkly.com with any questions.