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

# 通过偏好设置重放提示词

> 在保存的偏好设置（或未保存的草稿）中运行一个测试用提示词，而不消耗一次实际的补全调用。

通过路由引擎重放一次测试用提示词两次——一次在禁用该偏好设置的情况下（基线），一次在应用该偏好设置的情况下——这样你就能在保存之前，准确看到你的调整会带来什么变化。

两个路由共享相同的响应结构：

* `POST /api/v1/routing-preferences/{id}/test` — 针对**已保存**的偏好设置进行重放。
* `POST /api/v1/routing-preferences/test` — 针对**未保存的草稿**请求体进行重放（不写入数据库）。仪表盘的测试台在每次按键时都会调用它。

## 身份验证

需要携带具有 `billing` API 密钥作用域的 Bearer 令牌。

## 已保存偏好设置的请求体

<ParamField body="prompt" type="string" required>
  要重放的提示词。最多 4096 个字符。
</ParamField>

<ParamField body="mode" type="string" required>
  要模拟的调用方模式（例如 `"auto"`、`"fast"`、`"think"`）。
</ParamField>

## 草稿请求体

<ParamField body="prompt" type="string" required>
  要重放的提示词。最多 4096 个字符。
</ParamField>

<ParamField body="mode" type="string" required>
  要模拟的调用方模式。
</ParamField>

<ParamField body="draft" type="object" required>
  未保存的偏好设置数据体。结构与创建请求体相同，但不含 `scope` 和 `is_default`。字段包括：`name`、可选的 `description`、`rules`、`examples`、`confidence_floor_overrides`。其品牌安全校验、正则表达式编译校验以及供应商名称清理规则，与已持久化的路由完全一致。
</ParamField>

## 请求示例

<CodeGroup>
  ```bash saved theme={null}
  curl -X POST "https://www.hitheo.ai/api/v1/routing-preferences/$PREF_ID/test" \
    -H "Authorization: Bearer $THEO_API_KEY" \
    -H "Content-Type: application/json" \
    -d '{ "prompt": "Compare these two warranty sections", "mode": "auto" }'
  ```

  ```bash draft theme={null}
  curl -X POST https://www.hitheo.ai/api/v1/routing-preferences/test \
    -H "Authorization: Bearer $THEO_API_KEY" \
    -H "Content-Type: application/json" \
    -d '{
      "prompt": "Look at this clause",
      "mode": "auto",
      "draft": {
        "name": "ContractIQ Legal (draft)",
        "rules": [
          { "pattern": "\\b(clause|provision)\\b", "target_mode": "think", "confidence": 0.92 }
        ],
        "examples": []
      }
    }'
  ```

  ```typescript SDK theme={null}
  const diff = await theo.routingPreferences.test(prefId, {
    prompt: "Compare these two warranty sections",
    mode: "auto",
  });
  console.log(diff.baseline.resolved_mode);        // "fast"
  console.log(diff.with_preference.resolved_mode); // "think"
  ```
</CodeGroup>

## 响应

两个路由返回相同的结构。每个数据块都与你的调用方在真实补全请求中收到的 `routing` 遥测数据格式一致。

```json theme={null}
{
  "baseline": {
    "requested_mode": "auto",
    "resolved_mode": "fast",
    "promoted": false,
    "reason": "default"
  },
  "with_preference": {
    "requested_mode": "auto",
    "resolved_mode": "think",
    "promoted": true,
    "reason": "customer_preference",
    "explanation": "Routing Studio rule matched: \"clause\".",
    "customer_preference": {
      "rule_matched": "r_a4b8c01x9y",
      "examples_injected": 2
    }
  }
}
```

## 错误

* `400 routing_preference_invalid` — 草稿校验失败（供应商名称、无法编译的正则表达式等）。
* `404 not_found` — 已保存的偏好设置不存在，或调用方无权查看。


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