Skip to Content
API 參考Decisions 判斷

Decisions API

Decisions API 用來讓模型對一段內容做型別化判斷,而非生成文字。你提供要判斷的內容與一組問題,模型對每個問題返回一個結構化答案:是/否的機率、從選項中選出一個,或在分級量表上評分,並附上每個選項的機率與置信度。

適用於分類、路由、審核、評分、過濾等需要「程式直接依結果做分支」的情境。模型只能在你給定的選項與分級中作答,不會返回選項以外的內容,也不需要解析自由文字。

首次使用判斷模型時,建議先閱讀 Jev 使用指南,其中包含快速開始、問題設計、返回結果說明與情境範例。本頁為欄位層級參考。

端點

三條路徑背後是同一批模型、同一套計費,差別僅在請求與回應的格式。請依你使用的用戶端選擇:

路徑格式適用
POST https://api.ofox.ai/v1/decisionsOfoxAI 統一格式(問題為陣列)cURL、任意 HTTP 用戶端、OpenAI SDK
POST https://api.ofox.ai/openai/v1/decisions同上已將 OpenAI SDK 的 base_url 設為 https://api.ofox.ai/openai/v1 的專案
POST https://api.ofox.ai/typesafe/v1/systemoneTypeSafe 官方 System One 格式(問題為物件)TypeSafe 官方 SDK,或依 TypeSafe 官方文件撰寫的程式碼

認證方式與其他介面相同:Authorization: Bearer <你的 OFOXAI_API_KEY>。僅支援非串流,一次請求同步返回全部答案。

可用模型

模型 ID說明
typesafe/jev-latestTypeSafe Jev,專用判斷模型。僅限文字或 JSON 輸入,64K 上下文。可簡寫為 jev-latest
openai/gpt-6-luna三條路徑皆可使用,可讀取圖片(在訊息陣列中傳入 input_image)

支援此介面的完整模型列表請見模型頁 。對一般對話模型(如 openai/gpt-4o)呼叫會返回 endpoint_not_supported。

統一格式:/v1/decisions

請求參數

參數型別必填說明
modelstring✅模型 ID,如 typesafe/jev-latest
inputstring | object | array✅要判斷的內容,見輸入格式
questionsarray✅問題列表,每個元素為一個問題物件。答案依相同順序返回
safety_identifierstring—穩定的終端使用者 ID,僅對 OpenAI 模型生效

輸入格式

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。

問題物件

欄位適用型別說明
type全部predicate(是/否)、choice(單選)、score(分級評分)
name全部選填,但建議填寫。會原樣帶回答案中,便於對應。同一請求內不可重複
instructions全部問題本身。字串,或包含問題與參考資料的 JSON 物件
criteriapredicate選填,{ "true": "...", "false": "..." },說明「是」與「否」各自代表什麼
choiceschoice必填。選項陣列,每項為 { "value": "billing", "description": "Charges, refunds" },description 可省略。最多 255 項
levelsscore必填。依由低到高排列的級別陣列,每項為 { "label": "low", "description": "..." }。2–10 級

請求範例

Terminal
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 一一對應、順序相同。各型別答案的欄位:

型別欄位說明
predicateprobability答案為「是」的機率,0–1
choicechoice機率最高的選項
probabilities每個選項的機率,合計為 1
confidence模型對此次判斷的確定程度,0–1,見機率與置信度
scorescore依機率加權的級別值,從 0 開始,可能落在兩級之間(如 1.43)
legend級別編號與描述的對照
probabilities每一級的機率
confidence同上

TypeSafe 原生格式:/typesafe/v1/systemone

與 TypeSafe 官方 API  的請求與回應格式一致,適合直接使用 TypeSafe SDK 或遷移既有程式碼。與統一格式相比有以下不同:

統一格式 /v1/decisionsTypeSafe 原生格式
要判斷的內容inputstate
問題陣列,以 name 識別物件,鍵名即問題 ID
是/否問題type: "predicate",答案欄位 probabilitytype: "noul",答案欄位 noul
選項與級別choices / levels 陣列皆寫在 criteria 中:choice 使用 {選項: 描述} 物件,score 使用描述字串陣列
用量欄位prompt_tokens / completion_tokensinput_tokens / output_tokens
Terminal
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,其餘程式碼不變:

typesafe_sdk.py
# 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 仍照常返回)。

一次請求中的所有問題共用同一份輸入,將多個問題放進同一請求比拆成多次呼叫便宜得多,也更快。

限制

項目限制
請求主體最大 32 MiB
上下文Jev 為 64K token,超出返回 400
choice 選項最多 255 個
score 級別2–10 級
JSON 巢狀input/state、instructions、criteria 各自最多 64 層
串流不支援

常見錯誤

HTTP · type錯誤原文原因處理方式
400 invalid_request_errorquestion "a" has kind choice and requires criteria optionschoice 問題沒有 choices補上選項陣列
400 invalid_request_errorquestion name "a" is used more than once兩個問題的 name 相同改為不重複的名稱
400 invalid_request_errorToo many score levels. Must have at most 10 levels.score 級別超過 10 個合併級別,或拆成多個問題
400 invalid_request_errordecision input carries an "input_image" part, which Typesafe cannot read對 Jev 傳入了圖片移除圖片,或改用可讀取圖片的模型
400 invalid_request_errorInvalid request payload在 /v1/decisions 上使用了 TypeSafe 原生格式(state + 物件形式的 questions)改用統一格式,或改呼叫 /typesafe/v1/systemone
400 endpoint_not_supportedModel 'openai/gpt-4o' does not support the /v1/decisions endpoint on this platform.該模型不是判斷模型改用可用模型
404 model_not_foundModel 'typesafe/jev-9' not found模型 ID 寫錯使用 typesafe/jev-latest
404 invalid_request_errorUnsupported API endpoint.路徑寫成了 /v1/systemoneTypeSafe 原生格式的路徑為 /typesafe/v1/systemone

其他通用錯誤請見錯誤處理。

最後更新於