Repository
cortex-rest-api-demo
Build an LLM Chat app in 5 minutes Quickly connect to Snowflake's LLM REST API This repository shows you how to build a simple chat app using Snowflake's API. Quickly connect to Sn · License unknown · Install via pip · Maintenance unknown
- License
- Unknown
README
Build an LLM Chat app in 5 minutes
Jump ahead:
Overview
This repository shows you how to build a simple chat app using Snowflake's API.
Quickly connect to Snowflake's LLM REST API
curl "https://[ACCOUNT-IDENTIFIER].snowflakecomputing.com/api/v2/cortex/inference:complete" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_PERSONAL_ACCESS_TOKEN" \
-d '{
"model": "claude-3-5-sonnet",
"messages": [
{
"role": "user",
"content": "Write me a one line poem about Snowflake"
}
]
}'
Snowflake's API is compatible with OpenAI's spec
To reproduce:
-
Sign up for a new Snowflake account here. Activate your account by e-mail (see screenshot below), pick a username and password, and you should see a welcome screen.
<img width="300" src="https://github.com/user-attachments/assets/1a11cd4c-514d-4ac0-98b2-5e2207dc6698" />
Note: if you can't find your login info, search your inbox for an e-mail from "Snowflake Computing".
-
Generate a Personal Access Token (PAT) -- this is your API key -- by visiting Authentication Settings. Be sure to set the network policy exception for easy weekend hacking:
<img width="605" height="375" alt="Screenshot 2025-09-12 at 11 25 08 AM" src="https://github.com/user-attachments/assets/6ada1e18-4985-4bdd-a5a1-cbae7f78d8f9" />
-
Find your account identifier by clicking on your name in the bottom left corner of Snowflake's UI, and selecting
Connect a tool to Snowflake:<img width="220" alt="Screenshot 2025-04-15 at 9 08 27 PM" src="https://github.com/user-attachments/assets/d485f628-e397-4869-82d7-c5e1c1af24c0" />
<img width="450" src="https://github.com/user-attachments/assets/c4839cb9-585f-4af7-a7fb-40c328153786" />
-
That's it! Run the curl command in your terminal and observe the streaming output
Building your first app
-
Clone this repo.
-
Sign up for a new Snowflake account here. Activate your account by e-mail (see screenshot below), pick a username and password, and you should see a welcome screen.
<img width="300" src="https://github.com/user-attachments/assets/1a11cd4c-514d-4ac0-98b2-5e2207dc6698" />
Note: If you can't find your login info, search your inbox for an e-mail from "Snowflake Computing".
-
Generate a Personal Access Token (PAT) -- this is your API key -- by visiting Authentication Settings. Be sure to set the network policy exception for easy weekend hacking:
<img width="605" height="375" alt="Screenshot 2025-09-12 at 11 25 08 AM" src="https://github.com/user-attachments/assets/6ada1e18-4985-4bdd-a5a1-cbae7f78d8f9" />
-
Click on your name in the bottom left corner, and select
Connect a tool to Snowflake:<img width="220" alt="Screenshot 2025-04-15 at 9 08 27 PM" src="https://github.com/user-attachments/assets/d485f628-e397-4869-82d7-c5e1c1af24c0" />
-
Use the information in the connect dialog to fill in your
secrets.tomlfile:<img width="450" src="https://github.com/user-attachments/assets/c4839cb9-585f-4af7-a7fb-40c328153786" />
[snowflake] account = "[Account Identifier]" user = "[User Name]" api_key = "[Paste in your Personal Access Token here]" role = "[Role]" host = "[Account/Server URL]" -
Run
pip install -r requirements.txtto make sure you have all the dependencies working. -
Run
streamlit run streamlit.appand you should see a simple chat app ready to chat with you! Try changing the model used:mistral-large2,claude-3-5-sonnetorllama3.1-70band compare the chat interaction!