Decisions API
Decisions API 用來讓模型對一段內容做型別化判斷,而非生成文字。你提供要判斷的內容與一組問題,模型對每個問題返回一個結構化答案:是/否的機率、從選項中選出一個,或在分級量表上評分,並附上每個選項的機率與置信度。
適用於分類、路由、審核、評分、過濾等需要「程式直接依結果做分支」的情境。模型只能在你給定的選項與分級中作答,不會返回選項以外的內容,也不需要解析自由文字。
首次使用判斷模型時,建議先閱讀 Jev 使用指南,其中包含快速開始、問題設計、返回結果說明與情境範例。本頁為欄位層級參考。
端點
三條路徑背後是同一批模型、同一套計費,差別僅在請求與回應的格式。請依你使用的用戶端選擇:
認證方式與其他介面相同:Authorization: Bearer <你的 OFOXAI_API_KEY>。僅支援非串流,一次請求同步返回全部答案。
可用模型
支援此介面的完整模型列表請見模型頁 。對一般對話模型(如 openai/gpt-4o)呼叫會返回 endpoint_not_supported。
統一格式:/v1/decisions
請求參數
輸入格式
input 支援三種寫法:
- 文字:一個字串。
"input": "Customer message: I was charged twice, nobody has answered my two emails, and I need a refund today." - 結構化資料:一個 JSON 物件,原樣交給模型。問題中可用反引號引用欄位名稱,如
`message`。"input": { "ticket_id": 4812, "message": "I was charged twice.", "plan": "pro" } - 訊息陣列:
[{ "role", "content" }],content為字串或內容區塊列表,內容區塊僅支援input_text與input_image。圖片僅對可讀取圖片的模型有效,Jev 不讀取圖片,傳入圖片會返回 400。
問題物件
請求範例
cURL
curl https://api.ofox.ai/v1/decisions \
-H "Authorization: Bearer $OFOX_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "typesafe/jev-latest",
"input": "Customer message: I was charged twice, nobody has answered my two emails, and I need a refund today.",
"questions": [
{ "type": "predicate", "name": "is_frustrated", "instructions": "Is the customer frustrated?" },
{
"type": "choice",
"name": "category",
"instructions": "Which category does this ticket belong to?",
"choices": [
{ "value": "billing", "description": "Charges and refunds" },
{ "value": "bug", "description": "Product issue" },
{ "value": "other", "description": "Other" }
]
},
{
"type": "score",
"name": "urgency",
"instructions": "How quickly does a human need to respond?",
"levels": [
{ "label": "low", "description": "Within a week is fine" },
{ "label": "medium", "description": "Should respond soon" },
{ "label": "high", "description": "Must respond today" }
]
}
]
}'回應格式
{
"model": "typesafe/jev-latest",
"answers": [
{ "type": "predicate", "name": "is_frustrated", "probability": 0.97 },
{
"type": "choice",
"name": "category",
"choice": "billing",
"confidence": 1,
"probabilities": [
{ "value": "billing", "probability": 1 },
{ "value": "bug", "probability": 0 },
{ "value": "other", "probability": 0 }
]
},
{
"type": "score",
"name": "urgency",
"score": 2,
"confidence": 1,
"legend": { "0": "low: Within a week is fine", "1": "medium: Should respond soon", "2": "high: Must respond today" },
"probabilities": [
{ "value": 0, "label": "low", "probability": 0 },
{ "value": 1, "label": "medium", "probability": 0 },
{ "value": 2, "label": "high", "probability": 1 }
]
}
],
"usage": { "prompt_tokens": 407, "completion_tokens": 72, "total_tokens": 479 }
}answers 與 questions 一一對應、順序相同。各型別答案的欄位:
TypeSafe 原生格式:/typesafe/v1/systemone
與 TypeSafe 官方 API 的請求與回應格式一致,適合直接使用 TypeSafe SDK 或遷移既有程式碼。與統一格式相比有以下不同:
curl https://api.ofox.ai/typesafe/v1/systemone \
-H "Authorization: Bearer $OFOX_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "jev-latest",
"state": "Help! My payouts have been failing for 3 days.",
"questions": {
"is_urgent": { "type": "noul", "instructions": "Does this convey urgency?" },
"department": {
"type": "choice",
"instructions": "Which team should handle this?",
"criteria": {
"billing": "Payments, invoicing, refunds",
"technical": "Bugs, outages, integrations",
"sales": "Pricing, upgrades"
}
},
"frustration": {
"type": "score",
"instructions": "How frustrated is the customer?",
"criteria": ["Calm", "Frustrated", "Very angry"]
}
}
}'{
"model": "typesafe/jev-latest",
"answers": {
"is_urgent": { "type": "noul", "noul": 0.95 },
"department": {
"type": "choice",
"choice": "billing",
"confidence": 0.85,
"probabilities": { "billing": 0.9, "technical": 0.1, "sales": 0 }
},
"frustration": {
"type": "score",
"score": 1.03,
"confidence": 0.95,
"legend": { "0": "Calm", "1": "Frustrated", "2": "Very angry" },
"probabilities": { "0": 0, "1": 0.97, "2": 0.03 }
}
},
"usage": { "input_tokens": 399, "output_tokens": 73 }
}SDK 接入
OpenAI SDK
OpenAI 官方 SDK 提供 client.decisions.create(),將 base_url 指向 https://api.ofox.ai/v1 即可,請求主體使用統一格式。範例見上方 Python 分頁。需使用包含 Decisions API 的 SDK 版本(實測 openai Python 3.31.0 可用)。
TypeSafe SDK
TypeSafe 官方 SDK 將 base_url 指向 https://api.ofox.ai/typesafe,api_key 換成 OfoxAI API Key,其餘程式碼不變:
Python
# pip install typesafe-sdk
import os
from typesafe_sdk import TypeSafeClient, Noul, Choice, Score
with TypeSafeClient(base_url="https://api.ofox.ai/typesafe", api_key=os.environ["OFOX_API_KEY"]) as client:
r = client.system_one(
model="jev-latest",
state={"message": "I was charged twice, nobody has answered my two emails, and I need a refund today."},
questions={
"urgent": Noul(instructions="Is the customer asking for this to be handled today?"),
"dept": Choice(
instructions="Which team should handle this?",
criteria={"billing": "Charges, invoices, refunds", "technical": "Bugs, integrations", "sales": "Pricing, upgrades"},
),
"anger": Score(instructions="How upset is the customer?", criteria=["Calm", "Upset but polite", "Very angry"]),
},
)
print(r.nouls["urgent"].noul) # 0.98
print(r.choices["dept"].choice) # billing
print(r.scores["anger"].score) # 1.56機率與置信度
- 機率回答「答案是什麼」:
probability、probabilities是模型對各個答案的校準機率。 - 置信度回答「這次判斷是否可信」:
confidence由機率分布推導而來,分布越集中越高。兩個選項各為 0.5 時,choice仍會給出一個,但confidence很低。
常見做法是在程式中設定門檻:置信度高時自動執行,低時轉交人工或交由更強的模型複核。
計費
依 token 計費,單價請見模型頁 。typesafe/jev-latest 僅依輸入 token 計費,輸出不計費(completion_tokens / output_tokens 仍照常返回)。
一次請求中的所有問題共用同一份輸入,將多個問題放進同一請求比拆成多次呼叫便宜得多,也更快。
限制
常見錯誤
其他通用錯誤請見錯誤處理。