# 列出 API Key

列出当前账号的密钥元数据和当日用量。

GET `/api/settings/api-keys`

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

## 请求参数

此操作无需提交参数。

## 请求示例

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

**cURL**

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

## 响应

**200 · 示例响应**

```json
{
  "keys": [
    {
      "id": "key_4a5076aa-f9ab-46e6-b383-7b1374392dc4",
      "name": "Analytics",
      "kind": "api_key",
      "prefix": "sk_shishu_…EXAMPLE0",
      "status": "active",
      "createdAt": "2026-01-15T12:00:00.000Z",
      "expiresAt": null,
      "lastUsedAt": null,
      "revokedAt": null,
      "dailyLimit": 100,
      "usedToday": 0,
      "remainingToday": 100,
      "tasks": [
        "rednote"
      ]
    }
  ],
  "day": "2026-01-15"
}
```

**错误示例**

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

| 字段 | 类型 | 说明 |
| --- | --- | --- |
| `day` | YYYY-MM-DD | 统计用量的当前 UTC 日。 |
| `keys[].id` | string | API Key 记录 ID。 |
| `keys[].name` | string | API Key 的显示名称。 |
| `keys[].kind` | api\_key \| oauth | 密钥或已连接 OAuth 应用的记录类型。 |
| `keys[].prefix` | string | 用于识别的脱敏字符串。 |
| `keys[].status` | active \| revoked \| expired | 密钥状态。 |
| `keys[].createdAt` | ISO 8601 date-time | 创建时间。 |
| `keys[].expiresAt` | ISO 8601 date-time \| null | 可选到期时间。 |
| `keys[].lastUsedAt` | ISO 8601 date-time \| null | 最近一次计入额度的调用时间。 |
| `keys[].revokedAt` | ISO 8601 date-time \| null | 撤销时间。 |
| `keys[].dailyLimit` | integer \| null | 密钥每日调用上限。 |
| `keys[].usedToday` | integer | 当前 UTC 日内已使用次数。 |
| `keys[].remainingToday` | integer \| null | 本日剩余调用次数。 |
| `keys[].tasks` | string\[\] \| null | 权限范围列表。null 代表三个工作台工具。使用扩展数据 API 需显式包含 catalog。 |

## 错误状态

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

## 使用细节

-   已过期、已撤销和有效密钥都会列出。列表只显示脱敏数据。

## 同组接口

-   [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/>)
-   [GET 查看自动切换状态](<https://social2api.com/docs/api/settings-fallback-get/>)
-   [PATCH 更新自动切换状态](<https://social2api.com/docs/api/settings-fallback-update/>)
-   [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/api-keys-list/>
