跳至主要內容

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。

LiteLLM 會從 SNOWFLAKE_JWT(JWT 驗證所使用的相同環境變數)讀取權杖,並從 SNOWFLAKE_ACCOUNT_ID 讀取帳戶。請在 PAT 前加上 pat/,讓 LiteLLM 將其作為 PROGRAMMATIC_ACCESS_TOKEN 傳送,而不是 KEYPAIR_JWT。

import os
from litellm import completion

os.environ["SNOWFLAKE_JWT"] = "pat/<your-programmatic-access-token>"
os.environ["SNOWFLAKE_ACCOUNT_ID"] = "<orgname>-<account_name>"

response = completion(
model="snowflake/claude-sonnet-4-6",
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-6",
messages=[{"role": "user", "content": "Hello!"}],
)

將憑證作為參數傳遞​

from litellm import completion

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

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

當您傳入 api_base 時,請使用帳戶主機(https://<account>.snowflakecomputing.com,可選擇加上 /api/v2)。若缺少,LiteLLM 會附加 /api/v2,然後是 /cortex/v1/messages、/cortex/v1/chat/completions 或 /cortex/inference:embed 路徑;若 api_base 已經包含 /cortex/v1,就會產生重複且無效的 URL。

所有驗證選項請參閱 對 Cortex REST API 進行驗證。

使用方式​

from litellm import completion
import os

os.environ["SNOWFLAKE_JWT"] = "pat/<your-pat>"
os.environ["SNOWFLAKE_ACCOUNT_ID"] = "<orgname>-<account_name>"

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

支援的 OpenAI 參數​

temperature, max_tokens, max_completion_tokens, top_p, stream,
tools, tool_choice

Claude 模型也接受 thinking(見下文)。response_format 不受支援,且會引發 UnsupportedParamsError,除非已設定 drop_params。

串流​

from litellm import completion
import os

os.environ["SNOWFLAKE_JWT"] = "pat/<your-pat>"
os.environ["SNOWFLAKE_ACCOUNT_ID"] = "<orgname>-<account_name>"

response = completion(
model="snowflake/claude-sonnet-4-6",
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_JWT"] = "pat/<your-pat>"
os.environ["SNOWFLAKE_ACCOUNT_ID"] = "<orgname>-<account_name>"

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-6",
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 模型支援 extended thinking。直接傳入提供者的 thinking 參數;reasoning_effort 不是 Snowflake 支援的參數,且會引發 UnsupportedParamsError,除非已設定 drop_params。

from litellm import completion

response = completion(
model="snowflake/claude-sonnet-4-6",
messages=[{"role": "user", "content": "Solve: what is 127 * 389?"}],
thinking={"type": "enabled", "budget_tokens": 1024},
)
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_JWT"] = "pat/<your-pat>"
os.environ["SNOWFLAKE_ACCOUNT_ID"] = "<orgname>-<account_name>"

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 docs 與 Service 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