> ## Documentation Index
> Fetch the complete documentation index at: https://docs.tokenlab.sh/llms.txt
> Use this file to discover all available pages before exploring further.

# 更新 API Key

> 更新当前组织下已有的用户 API Key。

## 概览

该接口用于更新已有用户 API Key 的名称、额度、模型白名单、过期时间或状态。

## 请求体

PATCH 请求至少需要提供一个字段。

| 字段              | 类型             | 默认值 / 限制              | 说明                                                          |
| --------------- | -------------- | --------------------- | ----------------------------------------------------------- |
| `status`        | enum           | -                     | `active`, `inactive`, `revoked`                             |
| `name`          | string         | 长度 `1-50`             | 更新后的展示名称                                                    |
| `limitAmount`   | number \| null | 最小 `0`，输入上限 `1000000` | `null` = 不限额，`0` = 零额度，正数会被规范化为一个存储上限，且不能超过 `100000` USD 等值 |
| `limitCurrency` | enum           | 默认 `USD`              | 仅支持 USD。发送 `CNY` 会返回 `400 currency_retired`。                |
| `models`        | string\[]      | -                     | 更新后的模型白名单                                                   |
| `expiresAt`     | string \| null | RFC3339 datetime      | `null` 表示清除过期时间                                             |

## 说明

* Management API v1 故意不支持硬删除。
* `revoked` 更适合作为终态使用；如需恢复，通常建议新建一个 Key，而不是依赖后续“解封”流程。

## 示例

<RequestExample>
  ```bash cURL theme={null}
  curl -X PATCH "https://api.tokenlab.sh/v1/management/api-keys/key_abc123def456" \
    -H "Authorization: Bearer mt-your-management-token" \
    -H "Content-Type: application/json" \
    -d '{
      "status": "inactive",
      "limitAmount": 0
    }'
  ```
</RequestExample>

## 请求 / 响应

精确 schema 和响应字段请使用上方的交互式 OpenAPI 面板。

## Response example

<ResponseExample>
  ```json 200 OK theme={null}
  {
    "id": "key_abc123def456",
    "name": "Backend Worker",
    "key_prefix": "sk-live...",
    "status": "inactive",
    "limit_amount": 0,
    "limit_amount_decimal": "0",
    "used_amount": 148.25,
    "used_amount_decimal": "148.25",
    "models": [
      "gpt-5-mini",
      "claude-3-7-sonnet"
    ],
    "expires_at": "2026-12-31T23:59:59.000Z",
    "last_used_at": "2026-07-08T03:12:45.000Z",
    "created_at": "2026-07-01T10:00:00.000Z"
  }
  ```
</ResponseExample>

## Important fields

<ResponseField name="id" type="string">API key identifier used in follow-up Management API calls.</ResponseField>
<ResponseField name="name" type="string">Display name for the API key.</ResponseField>
<ResponseField name="key_prefix" type="string">Non-secret key prefix for display and support.</ResponseField>
<ResponseField name="status" type="string">One of `active`, `inactive`, or `revoked`.</ResponseField>
<ResponseField name="limit_amount" type="number | null">Spending cap in USD as a JSON number for display. `null` means unlimited.</ResponseField>
<ResponseField name="limit_amount_decimal" type="string | null">Exact spending cap in USD as a decimal string. `null` means unlimited.</ResponseField>
<ResponseField name="used_amount" type="number">Accumulated usage in USD as a JSON number for display.</ResponseField>
<ResponseField name="used_amount_decimal" type="string">Exact accumulated usage in USD as a decimal string.</ResponseField>
<ResponseField name="models" type="string[]">Per-key model allowlist. Empty array means no additional key-level model restriction.</ResponseField>
<ResponseField name="expires_at" type="string | null">ISO timestamp when the key expires, or `null` for no expiry.</ResponseField>
<ResponseField name="last_used_at" type="string | null">ISO timestamp for the most recent use, or `null` when unused.</ResponseField>
<ResponseField name="created_at" type="string">ISO creation timestamp.</ResponseField>
