Clarifai
Anthropic、OpenAI、Qwen、xAI、Gemini 以及大多數開源 LLM 都支援 Clarifai。
| 屬性 | 詳細資訊 |
|---|---|
| 說明 | Clarifai 是一個強大的 AI 平台,透過統一 API 提供存取多種 LLM 的能力。LiteLLM 使用相容 OpenAI 的介面,讓您能無縫整合 Clarifai 的模型。 |
| 提供者文件 | Clarifai ↗ |
| OpenAI compatible Endpoint for Provider | https://api.clarifai.com/v2/ext/openai/v1 |
| 支援的端點 | /chat/completions |
先決條件
uv add litellm
必要環境變數
若要取得您的 Clarifai Personal access token,請依照這個 連結。
os.environ["CLARIFAI_PAT"] = "CLARIFAI_API_KEY" # CLARIFAI_PAT
用法
import os
from litellm import completion
os.environ["CLARIFAI_API_KEY"] = ""
response = completion(
model="clarifai/openai.chat-completion.gpt-oss-20b",
messages=[{ "content": "Tell me a joke about physics?","role": "user"}]
)
串流支援
LiteLLM 支援與 Clarifai 模型的串流回應:
import litellm
for chunk in litellm.completion(
model="clarifai/openai.chat-completion.gpt-oss-20b",
api_key="CLARIFAI_API_KEY",
messages=[
{"role": "user", "content": "Tell me a fun fact about space."}
],
stream=True,
):
print(chunk.choices[0].delta)
工具呼叫(函式呼叫)
透過 LiteLLM 存取的 Clarifai 模型支援函式呼叫:
import litellm
tools = [{
"type": "function",
"function": {
"name": "get_weather",
"description": "Get current temperature for a given location.",
"parameters": {
"type": "object",
"properties": {
"location": {
"type": "string",
"description": "City and country e.g. Tokyo, Japan"
}
},
"required": ["location"],
"additionalProperties": False
},
}
}
}]
response = litellm.completion(
model="clarifai/openai.chat-completion.gpt-oss-20b",
api_key="CLARIFAI_API_KEY",
messages=[{"role": "user", "content": "What is the weather in Paris today?"}],
tools=tools,
)
print(response.choices[0].message.tool_calls)
Clarifai 模型
liteLLM 支援 Clarifai community 上的所有模型
🧠 OpenAI 模型
🤖 Anthropic 模型
🪄 xAI 模型
🔷 Google Gemini 模型
🧩 Qwen 模型
- Qwen3-30B-A3B-Instruct-2507
- Qwen3-30B-A3B-Thinking-2507
- Qwen3-14B
- QwQ-32B-AWQ
- Qwen2_5-VL-7B-Instruct
- Qwen3-Coder-30B-A3B-Instruct
- 更多...
💡 MiniCPM(OpenBMB)模型
🧬 Microsoft Phi 模型
- Phi-4-reasoning-plus
- phi-4
- 更多...
🦙 Meta Llama 模型
- Llama-3_2-3B-Instruct
- 更多...
🔍 DeepSeek 模型
搭配 LiteLLM Proxy 的用法
以下是如何使用 LiteLLM Proxy Server 呼叫 Clarifai
1. 將金鑰儲存在您的環境中
export CLARIFAI_PAT="CLARIFAI_API_KEY"
2. 啟動 proxy
- config.yaml
model_list:
- model_name: clarifai-model
litellm_params:
model: clarifai/openai.chat-completion.gpt-oss-20b
api_key: os.environ/CLARIFAI_PAT
litellm --config /path/to/config.yaml
# Server running on http://0.0.0.0:4000
3. 測試
- Curl Request
- OpenAI v1.0.0+
curl --location 'http://0.0.0.0:4000/chat/completions' \
--header 'Content-Type: application/json' \
--data ' {
"model": "clarifai-model",
"messages": [
{
"role": "user",
"content": "what llm are you"
}
]
}
'
import openai
client = openai.OpenAI(
api_key="anything",
base_url="http://0.0.0.0:4000"
)
response = client.chat.completions.create(
model="clarifai-model",
messages = [
{
"role": "user",
"content": "this is a test request, write a short poem"
}
]
)
print(response)
重要說明
- 指定模型名稱時,請務必在 Clarifai 模型 ID 前加上
clarifai/ - 使用您的 Clarifai Personal Access Token(PAT)作為 API 金鑰
- 使用量會透過 Clarifai 進行追蹤與計費
- API 速率限制受您的 Clarifai 帳戶設定影響
- 大多數 OpenAI 參數都支援,但某些進階功能可能因模型而異
常見問題
| Question | Answer |
|---|---|
| Can I use all Clarifai models with LiteLLM? | 大多數聊天完成模型都支援。請使用 Clarifai 模型 URL 作為 model。 |
| Do I need a separate Clarifai PAT? | 是,您必須使用有效的 Clarifai Personal Access Token。 |
| Is tool calling supported? | 是,前提是底層的 Clarifai 模型支援函式/工具呼叫。 |
| How is billing handled? | Clarifai 的使用量會透過 Clarifai 個別計費。 |