> ## 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.

# 創建護欄策略

> 創建一個新的護欄策略。

創建一個新的護欄策略。此操作具有冪等性——使用相同的 `Idempotency-Key` 請求頭會重放相同的響應。

創建策略**不會**自動將其綁定到某個密鑰。請使用 [PUT /api/v1/keys/{id}/guardrails](/api-reference/guardrails/key-binding) 為某個密鑰啓用該策略。

## 身份驗證

需要攜帶具有 `billing` API 密鑰作用域的 Bearer 令牌。

## 請求體

<ParamField body="name" type="string" required>
  策略名稱。1–128 個字符。不得引用上游供應商名稱。
</ParamField>

<ParamField body="description" type="string">
  自由文本描述。最多 512 個字符。
</ParamField>

<ParamField body="rules" type="object[]">
  最多 32 個規則對象。每條規則包含 `guardrail_id`、`phase`、`verdict`，以及可選的 `config` 配置包。
</ParamField>

<ParamField body="scope" type="string">
  `"personal"`（默認）或 `"team"`。團隊作用域需要一個活躍的組織以及 `manageWebhooks` 權限。
</ParamField>

<ParamField body="is_default" type="boolean">
  將此策略標記為其所在作用域的默認策略。每個作用域最多隻能有一個默認策略。
</ParamField>

## 請求示例

<CodeGroup>
  ```bash curl theme={null}
  curl -X POST https://www.hitheo.ai/api/v1/guardrail-policies \
    -H "Authorization: Bearer $THEO_API_KEY" \
    -H "Content-Type: application/json" \
    -d '{
      "name": "Compliance-strict",
      "description": "PII redaction + jailbreak deny.",
      "rules": [
        { "guardrail_id": "pii_redactor", "phase": "input", "verdict": "redact" },
        { "guardrail_id": "prompt_injection", "phase": "input", "verdict": "deny" }
      ]
    }'
  ```

  ```typescript SDK theme={null}
  const policy = await theo.guardrails.policies.create({
    name: "Compliance-strict",
    description: "PII redaction + jailbreak deny.",
    rules: [
      { guardrail_id: "pii_redactor", phase: "input", verdict: "redact" },
      { guardrail_id: "prompt_injection", phase: "input", verdict: "deny" },
    ],
  });
  ```
</CodeGroup>

## 錯誤

* `400 guardrail_policy_invalid` — 護欄 id 未知、內置護欄使用了不允許的判定結果、標籤中包含供應商名稱，或規則數量超出上限。
* `403 missing_scope` — API 密鑰缺少 `billing` 作用域。
* `409 conflict` — 該作用域下已存在設置為 `is_default: true` 的策略。


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