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

# 设置余额预警

> 替换余额预警配置

```
PUT /openapi/memorylake/admin/v1/billing/credit-balance/alert
```

替换余额预警配置。阈值须全部为 `percent_used` 或全部为 `tokens_remaining`（最多 5 个）；绝对值以 tokens 为单位。收件人是在团队所有者之外追加的，团队所有者始终会收到通知。如需停止预警，请将 `enabled` 设为 false。

<Note>
  **所需权限：** `credits:manage`
</Note>

### 请求体

<ParamField body="enabled" type="boolean" required>
  是否发送预警
</ParamField>

<ParamField body="thresholds" type="array" required>
  预警级别，须为同一类型；重复项会被去除

  <Expandable title="Balance Alert Threshold 对象">
    <ParamField body="thresholds[].type" type="string" required>阈值类型；同一请求中的所有阈值必须使用相同类型。可选值：`percent_used`、`tokens_remaining`。</ParamField>
    <ParamField body="thresholds[].value" type="integer" required>`percent_used` 取 1–99；`tokens_remaining` 取 1–1,000,000,000</ParamField>
  </Expandable>
</ParamField>

<ParamField body="notification_channel" type="object">
  省略则仅发送给团队所有者

  <Expandable title="Alert Recipients Channel 对象">
    <ParamField body="notification_channel.recipients" type="array" required>附加邮箱地址（团队所有者始终会收到预警）；重复项按不区分大小写去除</ParamField>
    <ParamField body="notification_channel.type" type="string" required>投递渠道。可选值：`email`。</ParamField>
  </Expandable>
</ParamField>

<RequestExample>
  ```bash cURL theme={null}
  curl -X PUT 'https://app.memorylake.cn/openapi/memorylake/admin/v1/billing/credit-balance/alert' \
    -H 'Authorization: Bearer sk_xxxxxx' \
    -H 'Content-Type: application/json' \
    -d '{
      "enabled": true,
      "thresholds": [
        {
          "type": "percent_used",
          "value": 1
        }
      ],
      "notification_channel": {
        "recipients": [
          "example"
        ],
        "type": "email"
      }
    }'
  ```
</RequestExample>

### 响应

<ResponseField name="data" type="object">
  <Expandable title="Balance Alert 对象">
    <ResponseField name="delivery_enabled" type="boolean">false 表示此部署完全不评估余额预警；设置会被保留但不生效</ResponseField>
    <ResponseField name="enabled" type="boolean">是否发送预警</ResponseField>
    <ResponseField name="is_default" type="boolean">true 表示尚未保存任何内容；采用所示的默认值（有订阅时为 `percent_used` 80 / 95，否则为 `tokens_remaining` 1,600,000 / 320,000）</ResponseField>

    <ResponseField name="notification_channel" type="object">
      预警的发送目标

      <Expandable title="Alert Recipients Channel 对象">
        <ResponseField name="recipients" type="array">附加邮箱地址，最多 5 个。团队所有者的邮箱也始终会收到预警</ResponseField>
        <ResponseField name="type" type="string">投递渠道。可选值：`email`。</ResponseField>
      </Expandable>
    </ResponseField>

    <ResponseField name="status" type="object">
      当前预警状态

      <Expandable title="Balance Alert Status 对象">
        <ResponseField name="state" type="string">`triggered` 表示预警已触发，且余额尚未恢复到预警水位以上。可选值：`ok`、`triggered`。</ResponseField>
        <ResponseField name="balance_tokens" type="integer">触发时的余额，以 tokens 计</ResponseField>

        <ResponseField name="threshold" type="object">
          触发的水位

          <Expandable title="Balance Alert Threshold 对象">
            <ResponseField name="type" type="string">`percent_used` 表示订阅周期（无订阅时为累计充入的全部额度）的已用比例达到 `value` 百分比时预警；`tokens_remaining` 表示余额降至 `value` tokens 时预警</ResponseField>
            <ResponseField name="value" type="integer">`percent_used` 取 1–99；`tokens_remaining` 取 1–1,000,000,000</ResponseField>
          </Expandable>
        </ResponseField>

        <ResponseField name="triggered_at" type="integer">当前生效预警的触发时间，Unix 秒级时间戳</ResponseField>
      </Expandable>
    </ResponseField>

    <ResponseField name="thresholds" type="array">
      预警级别；须为同一类型

      <Expandable title="Balance Alert Threshold 对象">
        <ResponseField name="type" type="string">`percent_used` 表示订阅周期（无订阅时为累计充入的全部额度）的已用比例达到 `value` 百分比时预警；`tokens_remaining` 表示余额降至 `value` tokens 时预警</ResponseField>
        <ResponseField name="value" type="integer">`percent_used` 取 1–99；`tokens_remaining` 取 1–1,000,000,000</ResponseField>
      </Expandable>
    </ResponseField>
  </Expandable>
</ResponseField>

<ResponseExample>
  ```json Success (200) theme={null}
  {
    "success": true,
    "message": "Operation completed successfully",
    "data": {
      "delivery_enabled": true,
      "enabled": true,
      "is_default": true,
      "notification_channel": {
        "recipients": [
          "example"
        ],
        "type": "email"
      },
      "status": {
        "state": "ok",
        "balance_tokens": 1200000,
        "threshold": {
          "type": "percent_used",
          "value": 1
        },
        "triggered_at": 1760000000
      },
      "thresholds": [
        {
          "type": "percent_used",
          "value": 1
        }
      ]
    }
  }
  ```
</ResponseExample>


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