# 读取计费用量摘要

读取当前 UTC 日的调用额度和包含今天在内最近 30 个 UTC 日的上游尝试数。

GET `/api/settings/billing`

- **认证** 控制台会话 Cookie。
- **成功状态** `200`

## 请求参数

此操作无需提交参数。

## 请求示例

JavaScript 示例可在本站已登录的浏览器中运行。cURL 和 Python 示例读取你本机的 cookies.txt Cookie 文件。请将会话 Cookie 视为私密凭据。

**cURL**

```bash
curl -i -X GET 'https://social2api.com/api/settings/billing' \
  --cookie ./cookies.txt
```

**Python**

```python
from urllib.error import HTTPError
from urllib.request import Request, HTTPCookieProcessor, build_opener
from http.cookiejar import MozillaCookieJar

request = Request(
    "https://social2api.com/api/settings/billing",
    method="GET",
)
cookies = MozillaCookieJar("./cookies.txt")
cookies.load(ignore_discard=True)
send = build_opener(HTTPCookieProcessor(cookies)).open
try:
    with send(request) as response:
        print(response.status, response.read().decode("utf-8"))
except HTTPError as error:
    print(error.code, error.read().decode("utf-8"))
```

**JavaScript**

```javascript
const response = await fetch("/api/settings/billing", {
  method: "GET",
  credentials: "same-origin",
});
console.log(response.status, await response.text());
```

## 响应

**200 · 示例响应**

```json
{
  "usage": {
    "day": "2026-01-15",
    "used": 0,
    "remaining": 100000,
    "dailyLimit": 100000,
    "periodStart": "2025-12-17",
    "periodUsed": 0
  }
}
```

**错误示例**

```json
{
  "error": "请先登录。"
}
```

| 字段 | 类型 | 说明 |
| --- | --- | --- |
| `usage.day` | YYYY-MM-DD | 当前 UTC 日期。 |
| `usage.used` | integer | 当日已尝试的上游调用数。 |
| `usage.remaining` | integer \| null | 当日剩余调用次数。不限额时为 null。 |
| `usage.dailyLimit` | integer \| null | 当日上游调用上限，null 为不限额。 |
| `usage.periodStart` | YYYY-MM-DD | 30 天窗口的首个 UTC 日期。 |
| `usage.periodUsed` | integer | 30 天窗口已尝试的上游调用数。 |

## 错误状态

| HTTP | 原因与处理 |
| --- | --- |
| `401` | 控制台会话缺失、过期或无效。 |
| `405` | 请求方法不受支持。 |
| `503` | 此部署未配置该控制台服务。 |

## 使用细节

-   此摘要以调用次数为单位；供应商实际费用可在调用明细中查看。

## 同组接口

-   [GET 读取设置与每日额度](<https://social2api.com/docs/api/settings-get/>)
-   [PATCH 更新偏好和每日额度](<https://social2api.com/docs/api/settings-update/>)
-   [GET 查询上游调用明细](<https://social2api.com/docs/api/settings-usage/>)
-   [GET 查看自动切换状态](<https://social2api.com/docs/api/settings-fallback-get/>)
-   [PATCH 更新自动切换状态](<https://social2api.com/docs/api/settings-fallback-update/>)
-   [GET 列出 API Key](<https://social2api.com/docs/api/api-keys-list/>)
-   [POST 创建 API Key](<https://social2api.com/docs/api/api-keys-create/>)
-   [PATCH 更新 API Key](<https://social2api.com/docs/api/api-keys-update/>)
-   [DELETE 撤销 API Key](<https://social2api.com/docs/api/api-keys-revoke/>)

规范页面：<https://social2api.com/docs/api/settings-billing/>
