> ## 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 を更新します。

## 概要

この endpoint では、既存 API Key の名前、利用上限、許可モデル、有効期限、状態を更新できます。

## リクエストボディ

PATCH リクエストでは少なくとも 1 つのフィールドを指定する必要があります。

| フィールド           | 型              | 既定値 / 制約              | 説明                                                             |
| --------------- | -------------- | --------------------- | -------------------------------------------------------------- |
| `status`        | enum           | -                     | `active`, `inactive`, `revoked`                                |
| `name`          | string         | 長さ `1-50`             | 更新後の表示名                                                        |
| `limitAmount`   | number \| null | 最小 `0`、入力上限 `1000000` | `null` = 無制限、`0` = 利用可能額 0、正の値は保存時に正規化され、`100000` USD 相当を超えません |
| `limitCurrency` | enum           | 既定 `USD`              | USD のみです。`CNY` を送信すると `400 currency_retired` が返されます。           |
| `models`        | string\[]      | -                     | 更新後のモデル許可リスト                                                   |
| `expiresAt`     | string \| null | RFC3339 datetime      | `null` は有効期限を解除します                                             |

## 補足

* Management API v1 ではハード削除は意図的にサポートしていません。
* `revoked` は通常終端状態として扱われます。再度キーが必要な場合は、新しいキーを作成するのが一般的です。

## 例

<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>
