跳至主要內容

Snowflake Cortex

LiteLLM 支援 Snowflake Cortex REST API 上的所有模型,包括 Anthropic(Claude)、OpenAI(GPT)、Meta(Llama)、Mistral、DeepSeek,以及 Snowflake 的模型。

說明Snowflake Cortex REST API 透過相容 OpenAI 與相容 Anthropic 的端點,提供對領先前沿 LLM 的存取。所有推論都在 Snowflake 的安全邊界內執行。
LiteLLM 提供者路由snowflake/
Provider DocsCortex REST API ↗
API EndpointsChat Completions: https://{account}.snowflakecomputing.com/api/v2/cortex/v1/chat/completions
Messages: https://{account}.snowflakecomputing.com/api/v2/cortex/v1/messages
Legacy: https://{account}.snowflakecomputing.com/api/v2/cortex/inference:complete
支援的 OpenAI 端點/chat/completions, /completions, /embeddings

提示:我們支援所有 Snowflake Cortex 模型。傳送 LiteLLM 請求時,請使用 model=snowflake/<model-name> 作為前綴。

驗證

Snowflake Cortex REST API 支援三種驗證方法。

最簡單的方法。在 Snowsight 的 User Menu → My Profile → Programmatic Access Tokens 中產生 PAT。

import os
from litellm import completion

os.environ["SNOWFLAKE_API_KEY"] = "pat/<your-programmatic-access-token>"
os.environ["SNOWFLAKE_API_BASE"] = "https://<account>.snowflakecomputing.com/api/v2/cortex/v1"

response = completion(
model="snowflake/claude-sonnet-4-5",
messages=[{"role": "user", "content": "Hello!"}],
)

JWT(金鑰配對驗證)

從 Snowflake 金鑰組產生 JWT。請參閱 Key-pair authentication

import os
from litellm import completion

os.environ["SNOWFLAKE_JWT"] = "<your-jwt-token>"
os.environ["SNOWFLAKE_ACCOUNT_ID"] = "<orgname>-<account_name>"

response = completion(
model="snowflake/claude-sonnet-4-5",
messages=[{"role": "user", "content": "Hello!"}],
)

將憑證作為參數傳遞

from litellm import completion

# Using PAT
response = completion(
model="snowflake/claude-sonnet-4-5",
messages=[{"role": "user", "content": "Hello!"}],
api_key="pat/<your-pat-token>",
api_base="https://<account>.snowflakecomputing.com/api/v2/cortex/v1",
)

# Using JWT
response = completion(
model="snowflake/claude-sonnet-4-5",
messages=[{"role": "user", "content": "Hello!"}],
api_key="<your-jwt-token>",
account_id="<orgname>-<account_name>",
)

關於所有驗證選項,請參閱 Authenticating to Cortex REST API

使用方式

from litellm import completion
import os

os.environ["SNOWFLAKE_API_KEY"] = "pat/<your-pat>"
os.environ["SNOWFLAKE_API_BASE"] = "https://<account>.snowflakecomputing.com/api/v2/cortex/v1"

response = completion(
model="snowflake/claude-sonnet-4-5",
messages=[{"role": "user", "content": "What is Snowflake Cortex?"}],
)
print(response.choices[0].message.content)

支援的 OpenAI 參數

temperature, max_tokens, top_p, stream, response_format,
tools, tool_choice

串流

from litellm import completion
import os

os.environ["SNOWFLAKE_API_KEY"] = "pat/<your-pat>"
os.environ["SNOWFLAKE_API_BASE"] = "https://<account>.snowflakecomputing.com/api/v2/cortex/v1"

response = completion(
model="snowflake/claude-sonnet-4-5",
messages=[{"role": "user", "content": "Write a haiku about data."}],
stream=True,
)

for chunk in response:
if chunk.choices[0].delta.content:
print(chunk.choices[0].delta.content, end="")

工具 / Function Calling

支援 Claude 和部分模型。LiteLLM 會自動將 OpenAI 工具格式轉換為 Snowflake 的 tool_spec 格式。

from litellm import completion
import os, json

os.environ["SNOWFLAKE_API_KEY"] = "pat/<your-pat>"
os.environ["SNOWFLAKE_API_BASE"] = "https://<account>.snowflakecomputing.com/api/v2/cortex/v1"

tools = [
{
"type": "function",
"function": {
"name": "get_weather",
"description": "Get the current weather for a location",
"parameters": {
"type": "object",
"properties": {
"location": {"type": "string", "description": "City name"}
},
"required": ["location"],
},
},
}
]

response = completion(
model="snowflake/claude-sonnet-4-5",
messages=[{"role": "user", "content": "What's the weather in San Francisco?"}],
tools=tools,
tool_choice="auto",
)

print(response.choices[0].message.tool_calls)

思考 / 推理

Cortex 上的 Claude 3.7 Sonnet、Claude 4 Opus 和 DeepSeek R1 支援延伸思考。LiteLLM 會將 reasoning_effort 轉換為提供者的 thinking 參數。

reasoning_effortbudget_tokens
"low"1024
"medium"2048
"high"4096
from litellm import completion

response = completion(
model="snowflake/claude-3-7-sonnet",
messages=[{"role": "user", "content": "Solve: what is 127 * 389?"}],
reasoning_effort="low",
)
print(response.choices[0].message.content)

提示快取

Snowflake Cortex 支援提示快取以降低成本:

  • OpenAI models:對於 ≥ 1,024 個 token 的提示進行隱式快取(不需要變更程式碼)
  • Claude models:透過 cache_control breakpoint 進行顯式快取

當快取的輸入 token ≥ 1,024 時,快取的輸入 token 會以一般輸入費率的 10% 計費(折扣 90%)。

詳情請參閱 Cortex REST API Billing & Cost Analysis

嵌入

from litellm import embedding
import os

os.environ["SNOWFLAKE_API_KEY"] = "pat/<your-pat>"
os.environ["SNOWFLAKE_API_BASE"] = "https://<account>.snowflakecomputing.com/api/v2/cortex/v1"

response = embedding(
model="snowflake/snowflake-arctic-embed-l-v2.0",
input=["Snowflake Cortex provides LLM inference"],
)
print(response.data[0]["embedding"][:5])

支援的模型

所有模型都可透過 snowflake/ 前綴使用。

提示

如需目前的模型可用性、速率限制與價格,請參閱官方 Cortex REST API docsService Consumption Table

聊天完成模型

模型litellm model nameFunction CallingVisionPrompt Caching
Claude Sonnet 4.5snowflake/claude-sonnet-4-5
Claude Sonnet 4.6snowflake/claude-sonnet-4-6
Claude 4 Sonnetsnowflake/claude-4-sonnet
Claude 4 Opussnowflake/claude-4-opus
Claude Haiku 4.5snowflake/claude-haiku-4-5
Claude 3.7 Sonnetsnowflake/claude-3-7-sonnet
Claude 3.5 Sonnetsnowflake/claude-3-5-sonnet
OpenAI GPT-4.1snowflake/openai-gpt-4.1
OpenAI GPT-5snowflake/openai-gpt-5
OpenAI GPT-5 Minisnowflake/openai-gpt-5-mini
OpenAI GPT-5 Nanosnowflake/openai-gpt-5-nano
DeepSeek R1snowflake/deepseek-r1
Mistral Large 2snowflake/mistral-large2
Llama 3.1 8Bsnowflake/llama3.1-8b
Llama 3.1 70Bsnowflake/llama3.1-70b
Llama 3.1 405Bsnowflake/llama3.1-405b
Llama 3.3 70Bsnowflake/llama3.3-70b
Llama 4 Mavericksnowflake/llama4-maverick
Snowflake Llama 3.3 70Bsnowflake/snowflake-llama-3.3-70b

嵌入模型

模型litellm model name
Snowflake Arctic Embed L v2.0snowflake/snowflake-arctic-embed-l-v2.0
Snowflake Arctic Embed M v2.0snowflake/snowflake-arctic-embed-m-v2.0