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

# 接入预算

> 列出、设置和移除来源的预算。

预算只在来源接近或超出时提醒，接入的应答和存储都不变。见[接入用量与预算](https://docs.molesignal.com/zh-Hans/streams.md#接入用量与预算)。

## 列出预算

```http theme={null}
GET /api/v1/streams/budgets
```

返回组织的所有预算，以及来源的名称和当前周期的使用情况。需要 `intake_usage.read`；在 `_sys` 组织中也可以用 `sys.telemetry.read`。未知的数值是 `null`。

## 设置预算

```http theme={null}
POST /api/v1/streams/budgets
```

设置一个来源的预算。一个来源最多一个预算，再次设置会修改原来的。需要 `intake_budgets.manage`。`_sys` 组织不能设预算。

| 字段 | 必填 | 说明 |
| - | - | - |
| `dimension` | 是 | `credential`、`stream` 或 `service`。 |
| `source_key` | 是 | 来源，取值同[接入用量](https://docs.molesignal.com/zh-Hans/api/streams/usage.md)返回的。平台自身的遥测、没有标注服务的事件和超出上限的服务不能设预算。 |
| `period` | 是 | `day` 或 `month`，按 UTC 自然日或自然月计算。 |
| `limit_size` | 是 | 单位 MiB，范围 1 到 1073741824。 |
| `warn_percent` | 否 | 预警比例，范围 0 到 99。填 `0` 只在用完时提醒。默认 80。 |
| `notify_user_ids` | 否 | 要通知的组织成员，最多 50 人。默认是设预算的人。服务账号必须指定。 |

```bash cURL theme={null}
curl -X POST "http://localhost:5080/api/v1/streams/budgets" \
  -H "authorization: Bearer $MS_TOKEN" \
  -H "content-type: application/json" \
  -d '{"dimension":"stream","source_key":"logs:app","period":"day","limit_size":102400}'
```

## 移除预算

```http theme={null}
DELETE /api/v1/streams/budgets/{budget_id}
```

返回 `204`。需要 `intake_budgets.manage`。


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