# 更新偏好和每日额度

保存控制台语言、每日调用限额和邮件提醒设置。

PATCH `/api/settings`

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

## 请求参数

| 参数 | 类型 | 位置 | 必填 | 说明 |
| --- | --- | --- | --- | --- |
| `Origin` | URI | `header` | 是 | 当前站点的完整来源。 |
| `locale` | zh \| en | `body` | 否 | 偏好语言。 |
| `dailyLimit` | integer \| null | `body` | 否 | 0–10,000,000 次，0 禁用实时调用，null 为不限额。新账号默认 100,000。 |
| `lowBalance` | boolean | `body` | 否 | 打开低额度邮件提醒。 |
| `lowBalanceThreshold` | integer | `body` | 否 | 1–10,000,000 次。剩余额度低于该值时触发提醒。 |
| `runFailed` | boolean | `body` | 否 | 打开任务失败及部分完成邮件提醒。 |

## 请求示例

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

**cURL**

```bash
curl -i -X PATCH 'https://social2api.com/api/settings' \
  --cookie ./cookies.txt \
  -H 'Content-Type: application/json' \
  -H 'Origin: https://social2api.com' \
  --data-binary '{
  "dailyLimit": 1000
}'
```

**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",
    method="PATCH",
    headers={
        "Content-Type": "application/json",
        "Origin": "https://social2api.com",
    },
    data="{\"dailyLimit\":1000}".encode("utf-8"),
)
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", {
  method: "PATCH",
  credentials: "same-origin",
  headers: {
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    "dailyLimit": 1000
  }),
});
console.log(response.status, await response.text());
```

## 响应

**200 · 示例响应**

```json
{
  "preferences": {
    "locale": "zh",
    "dailyLimit": 1000,
    "lowBalance": false,
    "lowBalanceThreshold": 1000,
    "runFailed": false
  },
  "usage": {
    "day": "2026-01-15",
    "used": 0,
    "remaining": 1000
  },
  "mailEnabled": false
}
```

**错误示例**

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

| 字段 | 类型 | 说明 |
| --- | --- | --- |
| `preferences.locale` | zh \| en | 设置与提醒使用的语言偏好。 |
| `preferences.dailyLimit` | integer \| null | 账号每日上游调用上限。 |
| `preferences.lowBalance` | boolean | 是否为低额度发送邮件。 |
| `preferences.lowBalanceThreshold` | integer | 低额度提醒阈值，单位为调用次数。 |
| `preferences.runFailed` | boolean | 是否为失败或部分完成的任务发送邮件。 |
| `preferences` | object | 还可包含账号保存的其它偏好。 |
| `usage.day` | YYYY-MM-DD | 当前 UTC 日期。 |
| `usage.used` | integer | 当日已尝试的上游调用数。 |
| `usage.remaining` | integer \| null | 当日剩余调用次数。不限额时为 null。 |
| `mailEnabled` | boolean | 部署是否配置邮件传输。邮件提醒还需验证邮箱。 |

## 错误状态

| HTTP | 原因与处理 |
| --- | --- |
| `400` | 请求格式或字段无效。 |
| `403` | 浏览器来源校验未通过。 |
| `401` | 控制台会话缺失、过期或无效。 |
| `405` | 请求方法不受支持。 |
| `503` | 此部署未配置该控制台服务。 |

## 使用细节

-   写请求须包含与站点完全相同的 Origin。
-   JSON 请求体最多 4,096 字节。仅允许文档列出的偏好字段。

## 同组接口

-   [GET 读取设置与每日额度](<https://social2api.com/docs/api/settings-get/>)
-   [GET 查询上游调用明细](<https://social2api.com/docs/api/settings-usage/>)
-   [GET 读取计费用量摘要](<https://social2api.com/docs/api/settings-billing/>)
-   [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-update/>
