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

# 判断を行う

> 対応する判断モデルを使い、アプリケーションの状態に対して型付きの質問を評価します。

アプリケーションでコードから直接利用できる構造化された回答が必要な場合は、`POST /v1/decisions` を使用します。対応モデルには TypeSafe Jev 1.13 (`typesafe/jev-1.13.0`)、Together Tev1 4B Experimental (`together/tev1-4b-experimental`)、Respan Span-01 (`respan/span-01:free` と `respan/span-01`) があります。

リクエストには以下を含めます。

* `state`: 評価する情報を含む文字列、オブジェクト、または配列。
* `questions`: 名前付きの質問のマップ。各質問の `type` を `noul`、`choice`、`score` のいずれかに設定し、`instructions` を含めます。対応する型は選択したモデルによって異なります。
* `model`: Phaseo のモデル ID。Jev 1.13 には `typesafe/jev-1.13.0` を使い、常に最新の Jev リリースを使うには `typesafe/jev-latest` を指定します。

Liquid D1 (`liquid-ai/d1:free`、`liquid-ai/d1` としても利用可能) と Perplexity Decider 27B (`perplexity/decider-27b`) は、3 種類すべての質問に対応しています。D1 は実験的な早期アクセス期間中は無料です。Decider は画像トークンを含む入力トークン 100 万個あたり 0.04 米ドルで、出力トークンは無料です。Decider を使うには Phaseo に Perplexity のプロバイダー認証情報を追加してください。画像を含む状態には PNG、JPEG、WebP の Base64 データ URL を使用し、リモート画像 URL には対応していません。選択式の質問は最大 255 個の選択肢、スコアの質問は最大 10 段階に対応します。どちらのモデルも呼び出す前に利用可能か確認してください。

Respan Span-01 の `state` は、先行するメッセージの `input` 配列と、アシスタントの `output` メッセージを含む会話の区間である必要があります。Span-01 は `noul` の質問にのみ対応します。`noul` の回答は対象の振る舞いが存在する確率で、`probabilities` には存在しない確率と観測できない確率も含まれます。

```json theme={null}
{
  "model": "respan/span-01:free",
  "state": {
    "input": [{ "role": "user", "content": "Please connect me to a person." }],
    "output": { "role": "assistant", "content": "I will connect you to support." }
  },
  "questions": {
    "escalation": {
      "type": "noul",
      "instructions": "Does the assistant offer a human handoff?"
    }
  }
}
```

`respan/span-01:free` は日次制限のある無料の Lite モデルで、Phaseo はこれを Respan の API モデル ID `span-01-free` に対応付けます。`respan/span-01` は Respan の API モデル ID `span-01-pro` に対応し、Respan が入力トークン 100 万個あたり 0.02 米ドルを請求します。出力トークンは無料です。Span-01 は早期アクセス段階のため、Respan が組織のアクセスを有効にする必要があります。これらのモデルを呼び出す前に、Respan API キーを Phaseo の Respan プロバイダー認証情報として追加してください。

回答には `questions` と同じキーが使われます。`choice` の回答には選択された選択肢、確率、信頼度が含まれます。`noul` の回答には 0～1 の確率が含まれ、`score` の回答には確率で重み付けしたスコア、凡例、確率、信頼度が含まれます。

Respan の例では、レスポンスは次のようになります。

```json theme={null}
{
  "answers": {
    "escalation": {
      "type": "noul",
      "noul": 0.73,
      "probabilities": {
        "true": 0.73,
        "false": 0.25,
        "not_observable": 0.02
      }
    }
  }
}
```

Jev は 1 回のリクエストで 3 種類の質問を組み合わせられます。Span-01 は `noul` の質問にのみ対応します。コピーして使える cURL、JavaScript、TypeScript SDK、Python SDK の例は[クイックスタート](../../quickstart)を参照してください。Jev 1.13 は入力トークン 100 万個あたり 0.042 米ドルで、出力トークンは無料です。

提供元の質問の意味については、TypeSafe の [API リファレンス](https://docs.typesafe.ai/api)を参照してください。

### Clefによる画像の判断

`cloudflare/clef`と`cloudflare/clef-flash`は、Cloudflare Workers AIを通じて3種類すべての質問と埋め込み画像に対応します。それぞれ65,536トークンのコンテキストウィンドウを備えています。入力料金は100万トークンあたりClefで0.24 USD、Clef Flashで0.09 USDです。

```json theme={null}
{
  "model": "cloudflare/clef-flash",
  "state": "Inspect the attached product photo.",
  "images": [{ "content_type": "image/png", "base64": "<base64 image bytes>" }],
  "questions": {
    "damaged": { "type": "noul", "instructions": "Is the product visibly damaged?" }
  }
}
```

`images`には`data:image/png;base64,...`の文字列も指定できます。ClefはPNG、JPEG、WebP画像を最大4枚受け付けます。各画像は最大4 MiBかつ1,600万画素、デコード後の画像データの合計は最大8 MiB、リクエスト本文は最大13 MiBです。リモートURLには対応していません。Cloudflareは画像形式と寸法を検証します。画像に対応していないモデルは画像リクエストを拒否します。

Clefは最大64個の質問を受け付けます。IDは英字、数字、アンダースコア、ピリオド、ハイフンからなる最大100文字です。選択式の質問には2〜255個の選択肢、スコア式の質問には2〜10段階が必要です。Cloudflareの[Clefドキュメント](https://developers.cloudflare.com/workers-ai/models/clef/)を参照してください。


## OpenAPI

````yaml ja/openapi/v1/openapi.localized.yaml POST /decisions
openapi: 3.0.3
info:
  title: Phaseo Gateway API
  description: OpenAI互換のエンドポイントを通じて、さまざまなAIモデルにアクセスするためのゲートウェイAPI。
  version: 1.0.0
  contact:
    name: Phaseo
    url: https://phaseo.app
    email: danielbutler500@gmail.com
servers:
  - url: https://api.phaseo.app/v1
    description: グローバルルーティング
security:
  - BearerAuth: []
tags:
  - name: Gateway
    description: Core Phaseo Gateway operations.
paths:
  /decisions:
    post:
      tags:
        - Gateway
      summary: 構造化された判断を行う
      description: TypeSafe Jev などの判断モデルを使い、構造化された状態に対して Noul、Choice、Score の型付き質問を評価します。
      operationId: makeDecision
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/DecisionsRequest'
      responses:
        '200':
          description: 構造化された判断のレスポンス
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/DecisionsResponse'
components:
  schemas:
    DecisionsRequest:
      type: object
      required:
        - model
        - state
        - questions
      properties:
        model:
          type: string
          description: Phaseo の正規モデル ID またはプロバイダーのモデルエイリアス。
          default: typesafe/jev-1.13.0
        state:
          description: モデルが評価する構造化された状態。
          oneOf:
            - type: string
            - type: object
              additionalProperties: true
            - type: array
              items: {}
        questions:
          type: object
          minProperties: 1
          maxProperties: 128
          additionalProperties:
            oneOf:
              - $ref: '#/components/schemas/DecisionNoulQuestion'
              - $ref: '#/components/schemas/DecisionChoiceQuestion'
              - $ref: '#/components/schemas/DecisionScoreQuestion'
        images:
          type: array
          maxItems: 4
          description: >-
            画像認識に対応する判断モデル用の埋め込み画像。ClefはPNG、JPEG、WebPを受け付けます。リモートURLには対応していません。各画像は最大4
            MiBかつ1,600万画素、デコード後のデータ合計は最大8 MiB、リクエスト本文は最大13 MiBです。
          items:
            oneOf:
              - type: string
                pattern: >-
                  ^[Dd][Aa][Tt][Aa]:image/(png|jpeg|webp);base64,[A-Za-z0-9+/]+={0,2}$
              - $ref: '#/components/schemas/DecisionImage'
        meta:
          type: boolean
          default: false
        echo_upstream_request:
          type: boolean
        debug:
          $ref: '#/components/schemas/DebugOptions'
        provider:
          $ref: '#/components/schemas/ProviderRoutingOptions'
        routing:
          $ref: '#/components/schemas/ProviderRoutingOptions'
        metadata:
          type: object
          additionalProperties: true
    DecisionsResponse:
      type: object
      properties:
        model:
          type: string
        answers:
          type: object
          additionalProperties: true
        usage:
          $ref: '#/components/schemas/DecisionsUsage'
        request_id:
          type: string
          nullable: true
        meta:
          type: object
          additionalProperties: true
    DecisionNoulQuestion:
      type: object
      required:
        - type
        - instructions
      properties:
        type:
          type: string
          enum:
            - noul
        instructions:
          $ref: '#/components/schemas/DecisionInstructions'
        criteria:
          type: object
          properties:
            'true':
              type: string
            'false':
              type: string
          additionalProperties: true
    DecisionChoiceQuestion:
      type: object
      required:
        - type
        - instructions
        - criteria
      properties:
        type:
          type: string
          enum:
            - choice
        instructions:
          $ref: '#/components/schemas/DecisionInstructions'
        criteria:
          type: object
          minProperties: 1
          additionalProperties:
            type: string
            nullable: true
    DecisionScoreQuestion:
      type: object
      required:
        - type
        - instructions
        - criteria
      properties:
        type:
          type: string
          enum:
            - score
        instructions:
          $ref: '#/components/schemas/DecisionInstructions'
        criteria:
          type: array
          minItems: 2
          items:
            type: string
    DecisionImage:
      type: object
      required:
        - content_type
        - base64
      properties:
        content_type:
          type: string
          enum:
            - image/png
            - image/jpeg
            - image/webp
        base64:
          type: string
          pattern: ^[A-Za-z0-9+/]+={0,2}$
    DebugOptions:
      type: object
      description: ゲートウェイのデバッグ設定です。これらのフラグがプロバイダーに転送されることはありません。
      properties:
        enabled:
          type: boolean
        return_upstream_request:
          type: boolean
        return_upstream_response:
          type: boolean
        trace:
          type: boolean
        trace_level:
          type: string
          enum:
            - summary
            - full
    ProviderRoutingOptions:
      type: object
      description: ゲートウェイでの選択に使用するプロバイダーのルーティング設定。
      properties:
        order:
          type: array
          items:
            type: string
        only:
          type: array
          items:
            type: string
        ignore:
          type: array
          items:
            type: string
        include_alpha:
          type: boolean
          description: ルーティングに alpha プロバイダーを含める（既定ではオフ）。
        allow_fallbacks:
          type: boolean
          nullable: true
          description: 失敗後に別の対象プロバイダーへフォールバックすることを許可します。
        require_parameters:
          type: boolean
          nullable: true
          description: ルーティング前に、要求されたパラメーターにプロバイダーが対応していることを必須にします。
        required_execution_region:
          type: string
          nullable: true
          description: 指定された実行リージョンに対応するプロバイダーにルーティングを限定します。
        required_data_region:
          type: string
          nullable: true
          description: 指定されたデータリージョンに対応するプロバイダーにルーティングを限定します。
        require_zero_data_retention:
          type: boolean
          nullable: true
          description: ゼロデータ保持に対応するプロバイダーにルーティングを限定します。
        data_collection:
          type: string
          nullable: true
          enum:
            - allow
            - deny
        zdr:
          type: boolean
          nullable: true
        enforce_distillable_text:
          type: boolean
          nullable: true
        quantizations:
          type: array
          nullable: true
          items:
            type: string
        sort:
          oneOf:
            - type: string
            - type: object
              additionalProperties: true
          description: このリクエストのプロバイダーを、価格、レイテンシ、スループットなどで並べ替えます。
        max_price:
          type: object
          properties:
            prompt:
              oneOf:
                - type: number
                - type: string
            completion:
              oneOf:
                - type: number
                - type: string
            image:
              oneOf:
                - type: number
                - type: string
            audio:
              oneOf:
                - type: number
                - type: string
            request:
              oneOf:
                - type: number
                - type: string
        preferred_min_throughput:
          oneOf:
            - type: number
            - type: object
              additionalProperties:
                type: number
        preferred_max_latency:
          oneOf:
            - type: number
            - type: object
              additionalProperties:
                type: number
    DecisionsUsage:
      type: object
      properties:
        input_tokens:
          type: integer
          minimum: 0
        output_tokens:
          type: integer
          minimum: 0
        total_tokens:
          type: integer
          minimum: 0
    DecisionInstructions:
      oneOf:
        - type: string
        - type: object
          additionalProperties: true
        - type: array
          items: {}
  securitySchemes:
    BearerAuth:
      type: http
      scheme: bearer
      description: Bearer トークンによる認証

````

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.