Decisions API
Decisions API は、テキストを生成するのではなく、コンテンツに対してモデルに型付きの判定を行わせるための API です。判定対象のコンテンツと一連の質問を渡すと、モデルは質問ごとに構造化された回答を返します。Yes/No の確率、選択肢からの単一選択、または段階スケールでのスコアのいずれかで、各選択肢の確率と信頼度が付きます。
分類、ルーティング、モデレーション、スコアリング、フィルタリングなど、「プログラムが結果をそのまま分岐に使う」場面に適しています。モデルは指定された選択肢と段階の中でしか回答せず、それ以外の内容は返しません。自由形式のテキストを解析する必要もありません。
判定モデルを初めて使用する場合は、まず Jev 利用ガイドを参照することを推奨します。クイックスタート、質問の設計、返却結果の説明、シナリオ例を掲載しています。このページはフィールド単位のリファレンスです。
エンドポイント
3 つのエンドポイントは同じモデル群と同じ課金体系を使用し、違いはリクエストとレスポンスの形式だけです。使用するクライアントに合わせて選択してください。
認証方法は他のエンドポイントと同じです:Authorization: Bearer <OFOXAI_API_KEY>。非ストリーミングのみに対応しており、1 回のリクエストですべての回答が同期的に返ります。
利用可能なモデル
この API に対応するモデルの一覧はモデルページ をご覧ください。通常の対話モデル(openai/gpt-4o など)で呼び出すと endpoint_not_supported が返ります。
統一フォーマット:/v1/decisions
リクエストパラメータ
入力形式
input は次の 3 つの形式に対応しています。
- テキスト:1 つの文字列。
"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 と 1 対 1 で対応し、順序も同じです。種類ごとの回答フィールドは次のとおりです。
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は確率分布から算出され、分布が集中しているほど高くなります。2 つの選択肢がそれぞれ 0.5 の場合でもchoiceはどちらか一方を返しますが、confidenceは低くなります。
一般的には、コード内でしきい値を設定し、信頼度が高ければ自動で処理し、低ければ人による確認やより高性能なモデルでの再確認に回します。
課金
トークン単位で課金されます。単価はモデルページ をご覧ください。typesafe/jev-latest は入力トークンのみ課金され、出力は課金されません(completion_tokens / output_tokens は通常どおり返ります)。
1 回のリクエスト内のすべての質問は同じ入力を共有するため、複数の質問を 1 回のリクエストにまとめるほうが、複数回に分けて呼び出すよりも大幅に安く、高速です。
制限
よくあるエラー
その他の共通エラーはエラー処理をご覧ください。