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

# 取得 API 金鑰

> 使用 CometAPI GET /api/token/{id}，依 ID 取得已驗證帳戶的一筆 API 金鑰記錄。

使用此端點可依 ID 取得一筆 API 金鑰記錄。

<Note>
  請先在 [Console → Personal Settings](https://www.cometapi.com/console/personal) 產生個人存取 Token，然後將其作為原始 `Authorization` header 值傳送。不要加上 `Bearer` 前綴。
</Note>

`id` 路徑參數是由 [列出 API 金鑰](./list-api-keys) 回傳的數字金鑰 ID。

## API 金鑰狀態

| Status | Meaning |
| ------ | ------- |
| `1`    | 已啟用     |
| `2`    | 已停用     |
| `3`    | 已過期     |
| `4`    | 已耗盡     |

## 回傳欄位

| Field                  | Type           | Description                                                                                            |
| ---------------------- | -------------- | ------------------------------------------------------------------------------------------------------ |
| `id`                   | integer        | 數字 API 金鑰 ID。請將此值搭配 [更新 API 金鑰](./update-api-key) 與 [刪除 API 金鑰](./delete-api-key) 使用。                  |
| `key`                  | string         | 由管理 API 回傳的 API 金鑰值。請將其視為機密，並在模型請求中以 `Authorization: Bearer $COMETAPI_KEY` 使用。                         |
| `status`               | integer        | 運作狀態。只有 `1` 表示此金鑰已啟用，可用於模型請求。                                                                          |
| `name`                 | string         | 供使用者辨識的金鑰顯示名稱。                                                                                         |
| `created_time`         | integer        | 金鑰建立時間的 Unix 時間戳（秒）。                                                                                   |
| `accessed_time`        | integer        | 金鑰上次使用時間的 Unix 時間戳（秒）。                                                                                 |
| `expired_time`         | integer        | 金鑰到期時間的 Unix 時間戳（秒）。`-1` 表示永不到期。                                                                       |
| `remain_quota`         | integer        | 以 CometAPI 內部配額單位計算的剩餘配額。                                                                              |
| `used_quota`           | integer        | 此金鑰已消耗的配額，單位為 CometAPI 內部配額單位。                                                                         |
| `unlimited_quota`      | boolean        | 此金鑰是否略過剩餘配額檢查。                                                                                         |
| `model_limits_enabled` | boolean        | 此金鑰是否啟用模型限制。                                                                                           |
| `model_limits`         | string         | 當 `model_limits_enabled` 為 `true` 時，此金鑰允許使用的 model ID，以逗號分隔。空字串表示未設定模型清單。                              |
| `allow_ips`            | string or null | IP 允許清單，以單一字串表示，項目之間以換行分隔。每個項目可以是單一 IPv4 位址、單一 IPv6 位址、IPv4 CIDR 或 IPv6 CIDR。`null` 或 `""` 表示沒有 IP 限制。 |
| `group`                | string         | 帳戶群組限制。空字串表示沒有明確的群組限制。                                                                                 |
| `cross_group_retry`    | boolean        | 是否啟用跨群組重試，以進行自動群組路由。                                                                                   |


## OpenAPI

````yaml api/openapi/api-keys/get-api-key.openapi.json GET /api/token/{id}
openapi: 3.1.0
info:
  title: Get API Key
  version: 1.0.0
servers:
  - url: https://api.cometapi.com
security:
  - accessTokenAuth: []
paths:
  /api/token/{id}:
    get:
      summary: Get a single API key
      description: Retrieve one API key record by ID for the authenticated account.
      operationId: getApiKey
      parameters:
        - name: id
          in: path
          required: true
          description: Numeric API key ID returned by the list endpoint.
          schema:
            type: integer
      responses:
        '200':
          description: API key record.
          content:
            application/json:
              schema:
                type: object
                required:
                  - success
                  - message
                  - data
                properties:
                  success:
                    type: boolean
                  message:
                    type: string
                  data:
                    $ref: '#/components/schemas/ApiKey'
              examples:
                success:
                  summary: API key record
                  value:
                    success: true
                    message: ''
                    data:
                      id: 1234
                      user_id: 5678
                      key: $COMETAPI_KEY
                      status: 1
                      name: production
                      created_time: 1766102400
                      accessed_time: 1766102400
                      expired_time: -1
                      remain_quota: 100000
                      unlimited_quota: false
                      model_limits_enabled: false
                      model_limits: ''
                      allow_ips: null
                      used_quota: 0
                      group: ''
                      cross_group_retry: false
      x-codeSamples:
        - lang: curl
          label: cURL
          source: |-
            curl https://api.cometapi.com/api/token/1234 \
              -H "Authorization: your-access-token"
components:
  schemas:
    ApiKey:
      type: object
      properties:
        id:
          type: integer
          description: >-
            Numeric API key ID. Use this value with the get, update, and delete
            endpoints.
          example: 1234
        user_id:
          type: integer
          description: Account user ID that owns the key.
          example: 5678
        key:
          type: string
          description: >-
            API key value returned by the management API. Treat it as a secret
            and use it as `Authorization: Bearer $COMETAPI_KEY` for model
            requests.
          example: $COMETAPI_KEY
        status:
          type: integer
          description: >-
            Operational status for the key. `1` means enabled, `2` disabled, `3`
            expired, and `4` exhausted. Only enabled keys are accepted by model
            endpoints.
          enum:
            - 1
            - 2
            - 3
            - 4
          example: 1
        name:
          type: string
          description: User-readable display name for the API key.
          example: production
          maxLength: 50
        created_time:
          type: integer
          description: Unix timestamp in seconds when the key was created.
          example: 1766102400
        accessed_time:
          type: integer
          description: >-
            Unix timestamp in seconds when the key was last used. Newly created
            keys may show the creation time until first use.
          example: 1766102400
        expired_time:
          type: integer
          description: >-
            Unix timestamp in seconds when the key expires. `-1` means no
            expiration.
          example: -1
        remain_quota:
          type: integer
          description: >-
            Remaining quota for this key in CometAPI internal quota units. When
            this reaches `0` and `unlimited_quota` is `false`, model requests
            are rejected as quota exhausted.
          example: 100000
        unlimited_quota:
          type: boolean
          description: Whether the key bypasses remaining-quota checks.
          example: false
        model_limits_enabled:
          type: boolean
          description: >-
            Whether model restrictions are active for this key. When `false`,
            `model_limits` is ignored.
          example: false
        model_limits:
          type: string
          description: >-
            Comma-separated model IDs allowed by this key when
            `model_limits_enabled` is `true`. Empty means no configured model
            list.
          example: ''
        allow_ips:
          type:
            - string
            - 'null'
          description: >-
            Optional IP allowlist stored as one newline-separated string. Each
            entry can be a single IPv4 address, single IPv6 address, IPv4 CIDR,
            or IPv6 CIDR. Example:
            `198.51.100.10\n203.0.113.0/24\n2001:db8::/32`. `null` or `""` means
            IP restrictions are disabled.
          example: |-
            198.51.100.10
            203.0.113.0/24
            2001:db8::/32
        used_quota:
          type: integer
          description: Quota already consumed by this key in CometAPI internal quota units.
          example: 0
        group:
          type: string
          description: >-
            Account group restriction for this key. Empty means no explicit
            group restriction.
          example: ''
        cross_group_retry:
          type: boolean
          description: >-
            Whether cross-group retry is enabled for automatic group routing.
            This is only meaningful when the key uses an auto-routed group such
            as `auto`.
          example: false
      additionalProperties: true
  securitySchemes:
    accessTokenAuth:
      type: apiKey
      in: header
      name: Authorization
      description: >-
        Personal access token copied from CometAPI Console > Personal Settings.
        Send the raw token value; do not prefix it with `Bearer`.

````