> ## Documentation Index
> Fetch the complete documentation index at: https://docs.aireiter.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Jev 意思決定インターフェース

> - 同期型の意思決定インターフェースであり、チャットインターフェースではありません。ストリーミング出力には対応していません
- コンテキスト `state` と複数の判定問題 `questions` を送信すると、1回のレスポンスで各問題の確率、選択肢、またはスコアが返されます
- 呼び出し時のモデル名には `jev` を指定してください


export const apiKeyUrl = 'https://aireiter.com/keys';

## Authorizations

<ParamField header="Authorization" type="string" required>
  APIキー、Bearer Token形式

  API Keyの取得：

  <a href={apiKeyUrl} target="_blank">API Key管理ページ</a>にアクセスしてAPI Keyを取得します

  ```
  Authorization: Bearer YOUR_API_KEY
  ```
</ParamField>

## Body

<ParamField body="model" type="string" required>
  モデル名。`jev` と固定で指定します。

  レスポンス内の `result.result.model` はアップストリームで実際に使用されたバージョン番号（例：`jev-1.13.0`）です。このフィールドはアップストリームから返されるため、リクエストにはバージョン番号を含めないでください。
</ParamField>

<ParamField body="input" type="object" required>
  判定内容。`state` と `questions` を含みます。

  <Expandable title="フィールドの説明">
    <ParamField body="state" type="string | object | array" required>
      判定対象のデータ。1つの文字列でも、オブジェクトや配列でも構いません。判定の完了に必要なデータのみを含め、APIキーやパスワードなどの機密情報は含めないでください。
    </ParamField>

    <ParamField body="questions" type="object" required>
      設問リスト（空にすることはできません）。キー名は自由に設定でき、各設問は1つのオブジェクトになります。

      各設問には `type` と `instructions` が必須です。

      * `noul` — 二者択一問題。返される `noul` は 0 〜 1 の範囲で、「はい」の確率を表します。`criteria` は任意で、形式は `{ "true": "どのような場合が「はい」か", "false": "どのような場合が「いいえ」か" }` です。
      * `choice` — 単一選択。`criteria` は必須で、「選択肢名 → 説明」のオブジェクトです。返される `choice` は選択された選択肢名です。
      * `score` — スコア評価。`criteria` は必須で、低い順から並んだ2つ以上の要素を持つ配列です。返される `score` は該当する段階の数値で、最初の項目は 0 となり、小数も可能です。例えば3段階の場合、`1.99` はほぼ3番目の項目に該当することを示します。
    </ParamField>
  </Expandable>
</ParamField>

1回のリクエストに複数の `noul`、`choice`、`score` を同時に含めることができます。`stream` は渡さないでください。本エンドポイントは1回の完全なJSONのみを返します。

## Response

レスポンスボディは上流のオリジナルの JSON であり、本インターフェースでは変更を加えません。判定結果は `result.result.answers` に格納されます。

<ResponseField name="success" type="boolean">
  リクエストが成功したかどうか
</ResponseField>

<ResponseField name="errors" type="array">
  エラー一覧。成功時は空の配列
</ResponseField>

<ResponseField name="messages" type="array">
  追加メッセージ。メッセージがない場合は空の配列
</ResponseField>

<ResponseField name="result" type="object">
  上流の実行結果

  <Expandable title="フィールド説明">
    <ResponseField name="state" type="string">
      実行ステータス。`Completed` は完了を表します
    </ResponseField>

    <ResponseField name="result" type="object">
      モデルの回答

      <Expandable title="フィールド説明">
        <ResponseField name="model" type="string">
          上流で実際に使用されたバージョン番号（例：`jev-1.13.0`）
        </ResponseField>

        <ResponseField name="answers" type="object">
          各設問の結果。キー名はリクエスト内の設問名と一致します。

          * `noul`：`{ "type": "noul", "noul": 0.49 }`。`0.8` 以上は「はい」、`0.2` 以下は「いいえ」と見なすことができ、`0.5` に近い値は判断がつかないことを表します。
          * `choice`：`choice` は選択された選択肢名、`probabilities` は各選択肢の確率、`confidence` は信頼度です。
          * `score`：`score` はスコア、`legend` はランクのインデックスを送信したテキストにマッピングします。
        </ResponseField>

        <ResponseField name="usage" type="object">
          トークン使用量

          <Expandable title="フィールド説明">
            <ResponseField name="input_tokens" type="integer">
              入力トークン数
            </ResponseField>

            <ResponseField name="output_tokens" type="integer">
              出力トークン数
            </ResponseField>
          </Expandable>
        </ResponseField>
      </Expandable>
    </ResponseField>
  </Expandable>
</ResponseField>

## 使用示例

<RequestExample>
  ```bash cURL theme={null} theme={null}
  curl https://aireiter.com/api/v1/systemone \
    -H "Authorization: Bearer $API_KEY" \
    -H "Content-Type: application/json" \
    -d '{
      "model": "jev",
      "input": {
        "state": "The payment API timed out.",
        "questions": {
          "is_urgent": {
            "type": "noul",
            "instructions": "Does this need a person right now?"
          }
        }
      }
    }'
  ```

  ```python Python theme={null} theme={null}
  import os
  import requests

  response = requests.post(
      "https://aireiter.com/api/v1/systemone",
      headers={"Authorization": f"Bearer {os.environ['API_KEY']}"},
      json={
          "model": "jev",
          "input": {
              "state": "The payment API timed out.",
              "questions": {
                  "is_urgent": {
                      "type": "noul",
                      "instructions": "Does this need a person right now?",
                  }
              },
          },
      },
  )
  print(response.json()["result"]["result"]["answers"])
  ```

  ```javascript JavaScript theme={null} theme={null}
  const response = await fetch("https://aireiter.com/api/v1/systemone", {
    method: "POST",
    headers: {
      Authorization: `Bearer ${process.env.API_KEY}`,
      "Content-Type": "application/json",
    },
    body: JSON.stringify({
      model: "jev",
      input: {
        state: "The payment API timed out.",
        questions: {
          is_urgent: {
            type: "noul",
            instructions: "Does this need a person right now?",
          },
        },
      },
    }),
  });

  const data = await response.json();
  console.log(data.result.result.answers);
  ```
</RequestExample>

<ResponseExample>
  ```json theme={null} theme={null}
  {
    "result": {
      "state": "Completed",
      "result": {
        "model": "jev-1.13.0",
        "answers": {
          "is_urgent": {
            "type": "noul",
            "noul": 0.49
          }
        },
        "usage": {
          "input_tokens": 280,
          "output_tokens": 23
        }
      }
    },
    "success": true,
    "errors": [],
    "messages": []
  }
  ```
</ResponseExample>

## 複数質問の例

`choice` と `score` は、`noul` と同じリクエストに含めることができます。

```json theme={null} theme={null}
{
  "model": "jev",
  "input": {
    "state": {
      "ticket": "決済APIが断続的にタイムアウトし、データベースのコネクションプールが枯渇に近づいています。"
    },
    "questions": {
      "next_action": {
        "type": "choice",
        "instructions": "最も安全な次のステップを選択",
        "criteria": {
          "rollback": "直近の変更をロールバック",
          "observe": "監視を継続し、ログをサンプリング"
        }
      },
      "risk": {
        "type": "score",
        "instructions": "今回の障害のリスクを評価",
        "criteria": ["低", "中", "高", "極高"]
      },
      "escalate": {
        "type": "noul",
        "instructions": "人的エスカレーションが必要かどうか"
      }
    }
  }
}
```

## 注意事项

* 本エンドポイントはチャットエンドポイントではないため、`messages` を渡すことはできず、`stream` を渡すこともできません。
* コンテキストウィンドウは 32000 トークンです。
* 処理失敗時でも HTTP ステータスコードが 200 のままの場合がありますので、`success` と `errors` の両方を確認してください。認証失敗時は `401`、`model` の欠落または不正な JSON の場合は `400`、モデルが存在しない場合は `404` が返されます。
