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

# 安全護欄

> 對每個 API 請求強制執行組織策略。安全護欄控制可使用的模型、設置消費限額並配置資料保留策略，一切均可集中管理。

ARouter 安全護欄允許組織管理員強制執行適用於其組織內所有 API key 和所有請求的策略。

## 安全護欄的控制範圍

| 控制項         | 描述                |
| ----------- | ----------------- |
| **模型允許清單**  | 限制成員可使用的模型        |
| **提供商允許清單** | 限制請求可路由到的提供商      |
| **消費限額**    | 每個 key 和每個組織的預算上限 |
| **頻率限制**    | 每個 key 或成員的請求頻率限制 |
| **資料策略**    | ZDR 強制執行、資料收集限制   |

## 消費限額

為任意 API key 設置硬性信用額度限制。超出限額的請求將被拒絕並回傳 `402` 錯誤。

### 透過控制台

前往 [API Keys](https://arouter.ai/keys) → 編輯 Key → 設置**信用限額**。

### 透過 API

```bash theme={null}
curl -X PATCH https://api.arouter.ai/api/v1/keys/{key_hash} \
  -H "Authorization: Bearer lr_admin_xxxx" \
  -H "Content-Type: application/json" \
  -d '{"limit_usd": 50.00}'
```

| 欄位          | 類型       | 描述                       |
| ----------- | -------- | ------------------------ |
| `limit_usd` | `number` | 最大累計消費（美元）。`null` = 無限制。 |

達到限額時：

```json theme={null}
{"error": {"code": 402, "message": "Credit limit exceeded for this API key.", "metadata": {"limit_usd": 50.00, "used_usd": 50.01}}}
```

## 頻率限制

```bash theme={null}
curl -X PATCH https://api.arouter.ai/api/v1/keys/{key_hash} \
  -H "Authorization: Bearer lr_admin_xxxx" \
  -H "Content-Type: application/json" \
  -d '{"rate_limit": {"requests_per_minute": 60, "requests_per_day": 1000}}'
```

| 欄位                    | 類型        | 描述                     |
| --------------------- | --------- | ---------------------- |
| `requests_per_minute` | `integer` | 每分鐘最大請求數。`null` = 無限制。 |
| `requests_per_day`    | `integer` | 每天最大請求數。`null` = 無限制。  |

## 模型允許清單

```bash theme={null}
curl -X PATCH https://api.arouter.ai/api/v1/keys/{key_hash} \
  -H "Authorization: Bearer lr_admin_xxxx" \
  -H "Content-Type: application/json" \
  -d '{"allowed_models": ["openai/gpt-5.4", "anthropic/claude-sonnet-4.6", "google/gemini-2.5-flash"]}'
```

## 提供商允許清單

```bash theme={null}
curl -X PATCH https://api.arouter.ai/api/v1/keys/{key_hash} \
  -H "Authorization: Bearer lr_admin_xxxx" \
  -H "Content-Type: application/json" \
  -d '{"allowed_providers": ["OpenAI", "Anthropic"]}'
```

## 資料策略強制執行

```bash theme={null}
curl -X PATCH https://api.arouter.ai/api/v1/keys/{key_hash} \
  -H "Authorization: Bearer lr_admin_xxxx" \
  -H "Content-Type: application/json" \
  -d '{"enforce_zdr": true}'
```

## 護欄層級

策略按以下順序應用（最嚴格者優先）：

```
組織預設設定
  └── API Key 覆蓋
        └── 每請求提供商物件
```

## 相關文件

* [Key 管理](/zh-Hant/guides/key-management)
* [ZDR](/zh-Hant/guides/features/zdr)
* [組織管理](/zh-Hant/guides/administration/organization-management)
* [使用量計費](/zh-Hant/guides/administration/usage-accounting)
