> ## 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。使用 `typesafe/jev-1.13.0` 指定 Jev 1.13，或使用 `typesafe/jev-latest` 跟随最新 Jev 版本。

Liquid D1（`liquid-ai/d1:free`，也可使用 `liquid-ai/d1`）和 Perplexity Decider 27B (`perplexity/decider-27b`) 支持全部三种问题类型。D1 在实验性早期访问期间免费。Decider 每百万输入 token 收费 0.04 美元，包括图像 token；输出 token 免费。使用 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 按每百万输入 token 0.02 美元计费；输出 token 免费。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 支持在同一请求中混合全部三种问题类型；Span-01 仅支持 `noul` 问题。请参阅[快速开始](../../quickstart)，获取可直接复制的 cURL、JavaScript、TypeScript SDK 和 Python SDK 示例。Jev 1.13 按每百万输入 token 0.042 美元计费；输出 token 免费。

有关上游问题语义，请参阅 TypeSafe 的 [API 参考](https://docs.typesafe.ai/api)。

### 使用Clef进行图像决策

`cloudflare/clef`和`cloudflare/clef-flash`通过Cloudflare Workers AI支持全部三种问题类型和嵌入图像。两者的上下文窗口均为65,536个令牌。输入价格为每百万令牌Clef 0.24美元、Clef Flash 0.09美元。

```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 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 zh-Hans/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.