# 查看自动切换状态

返回账号的自动切换设置、供应商健康状态和最近 50 条切换记录。

GET `/api/settings/fallback`

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

## 请求参数

此操作无需提交参数。

## 请求示例

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

**cURL**

```bash
curl -i -X GET 'https://social2api.com/api/settings/fallback' \
  --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/fallback",
    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/fallback", {
  method: "GET",
  credentials: "same-origin",
});
console.log(response.status, await response.text());
```

## 响应

**200 · 示例响应**

```json
{
  "enabled": true,
  "providers": [
    {
      "id": "tikhub",
      "label": "TikHub",
      "configured": false,
      "status": "missing_config",
      "tasks": [
        "rednote",
        "douyin",
        "channels"
      ],
      "cooldownUntil": null,
      "lastError": null
    },
    {
      "id": "dataxapi",
      "label": "DataXAPI",
      "configured": false,
      "status": "missing_config",
      "tasks": [
        "rednote",
        "douyin",
        "channels"
      ],
      "cooldownUntil": null,
      "lastError": null
    },
    {
      "id": "socialtoai",
      "label": "SocialToAI",
      "configured": false,
      "status": "missing_config",
      "tasks": [
        "rednote",
        "douyin",
        "channels"
      ],
      "cooldownUntil": null,
      "lastError": null
    }
  ],
  "events": []
}
```

**错误示例**

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

| 字段 | 类型 | 说明 |
| --- | --- | --- |
| `enabled` | boolean | 该账号是否允许自动切换数据源。 |
| `providers[].id` | string | 供应商 ID。 |
| `providers[].label` | string | 供应商显示名称。 |
| `providers[].configured` | boolean | 当前部署是否配置该供应商。 |
| `providers[].status` | missing\_config \| unchecked \| healthy \| cooldown | 当前实例的供应商状态。 |
| `providers[].tasks` | string\[\] | 该供应商在当前部署启用的任务 ID。 |
| `providers[].cooldownUntil` | ISO 8601 date-time \| null | 当前冷却结束时间。 |
| `providers[].lastError` | string \| null | 最近记录的供应商故障原因。 |
| `events[].id` | string | 切换记录 ID。 |
| `events[].at` | ISO 8601 date-time | 记录时间。 |
| `events[].task` | string | 触发切换的取数任务。 |
| `events[].from` | string | 来源供应商 ID。 |
| `events[].to` | string | 目标供应商 ID。 |
| `events[].reason` | string | 触发切换的原因。 |

## 错误状态

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

## 使用细节

-   默认依次尝试 TikHub、DataXAPI、SocialToAI，跳过未配置、冷却或不支持输入的供应商。关闭自动切换时只尝试第一个已配置且适用的供应商。

## 同组接口

-   [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-billing/>)
-   [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-fallback-get/>
