更新 API Key

修改当前账号下指定密钥的说明、到期时间、限额或任务权限。

PATCH/api/settings/api-keys/{id}
认证
控制台会话 Cookie。
成功状态
200

请求参数

参数类型位置必填说明
idstringpath是API Key 记录 ID,格式 key_<UUID>。
OriginURIheader是当前站点的完整来源。
namestringbody否去空白后 1–60 个字符。
expiresAtISO 8601 date-time | nullbody否带时区的未来时间,接受 Z 或数值时区偏移,保存为 UTC。null 为永不过期。
dailyLimitinteger | nullbody否0–10,000,000 次,null 为不设密钥自己的限额。
tasksstring[] | nullbody否从 rednote、douyin、channels、catalog 中选择非空且无重复的权限列表。null 只包含工作台工具。普通 API Key 可显式选择 catalog。

请求示例

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

cURL
curl -i -X PATCH 'https://social2api.com/api/settings/api-keys/key_4a5076aa-f9ab-46e6-b383-7b1374392dc4' \
  --cookie ./cookies.txt \
  -H 'Content-Type: application/json' \
  -H 'Origin: https://social2api.com' \
  --data-binary '{
  "dailyLimit": 250
}'
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/key_4a5076aa-f9ab-46e6-b383-7b1374392dc4",
    method="PATCH",
    headers={
        "Content-Type": "application/json",
        "Origin": "https://social2api.com",
    },
    data="{\"dailyLimit\":250}".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
const response = await fetch("/api/settings/api-keys/key_4a5076aa-f9ab-46e6-b383-7b1374392dc4", {
  method: "PATCH",
  credentials: "same-origin",
  headers: {
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    "dailyLimit": 250
  }),
});
console.log(response.status, await response.text());

响应

200 · 示例响应
{
  "key": {
    "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": 250,
    "usedToday": 0,
    "remainingToday": 250,
    "tasks": [
      "rednote"
    ]
  }
}
错误示例
{
  "error": "请先登录。"
}
字段类型说明
key.idstringAPI Key 记录 ID。
key.namestringAPI Key 的显示名称。
key.kindapi_key | oauth密钥或已连接 OAuth 应用的记录类型。
key.prefixstring用于识别的脱敏字符串。
key.statusactive | revoked | expired密钥状态。
key.createdAtISO 8601 date-time创建时间。
key.expiresAtISO 8601 date-time | null可选到期时间。
key.lastUsedAtISO 8601 date-time | null最近一次计入额度的调用时间。
key.revokedAtISO 8601 date-time | null撤销时间。
key.dailyLimitinteger | null密钥每日调用上限。
key.usedTodayinteger当前 UTC 日内已使用次数。
key.remainingTodayinteger | null本日剩余调用次数。
key.tasksstring[] | null权限范围列表。null 代表三个工作台工具。使用扩展数据 API 需显式包含 catalog。

错误状态

HTTP原因与处理
400请求格式或字段无效。
403浏览器来源校验未通过。
401控制台会话缺失、过期或无效。
405请求方法不受支持。
413请求体超出 4,096 字节。
415需要 application/json 请求体。
500账户服务暂时不可用。
503此部署未配置该控制台服务。
404未找到该账号拥有的密钥。
409密钥已经撤销。

使用细节

  • 写请求须包含与站点完全相同的 Origin。
  • JSON 请求体最多 4,096 字节。
  • 至少提交一个可写属性。密钥值保持原样。