> ## 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 は、現在の管理トークンに紐づく組織内に、新しい `type=user` API Key を作成します。

## リクエストボディ

| フィールド           | 型              | 既定値 / 制約                       | 説明                                                                   |
| --------------- | -------------- | ------------------------------ | -------------------------------------------------------------------- |
| `name`          | string         | 必須、既定値 `Default Key`、長さ `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` は期限なしを意味します                                                   |

## 補足

* 完全な API Key 値はレスポンスで一度だけ返されます。
* `models: []` は、組織ポリシー以外の追加制限がないことを意味します。
* `limitAmount: 0` は有効だが利用可能額 0 のキーを作成します。後から更新できます。

## 例

<RequestExample>
  ```bash cURL theme={null}
  curl -X POST "https://api.tokenlab.sh/v1/management/api-keys" \
    -H "Authorization: Bearer mt-your-management-token" \
    -H "Content-Type: application/json" \
    -d '{
      "name": "Backend Worker",
      "limitAmount": 500,
      "models": ["veo3.1", "kling-3.0-video"],
      "expiresAt": "2026-12-31T23:59:59Z"
    }'
  ```
</RequestExample>

## リクエスト / レスポンス

正確な schema とレスポンス項目は、上部のインタラクティブな OpenAPI パネルを参照してください。

## Response example

<ResponseExample>
  ```json 201 Created theme={null}
  {
    "id": "key_abc123def456",
    "name": "Backend Worker",
    "key": "sk-live-redacted",
    "key_prefix": "sk-live...",
    "status": "active",
    "limit_amount": 500,
    "limit_amount_decimal": "500",
    "used_amount": 0,
    "used_amount_decimal": "0",
    "models": [
      "veo3.1",
      "kling-3.0-video"
    ],
    "expires_at": "2026-12-31T23:59:59.000Z",
    "last_used_at": null,
    "created_at": "2026-07-08T03:00:00.000Z"
  }
  ```
</ResponseExample>

## Important fields

<ResponseField name="key" type="string">Full secret API key value. It is returned only once on creation.</ResponseField>
<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>
