> ## 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/ 通过分页列出已认证账户的 API 密钥。

使用此端点可列出属于已认证 CometAPI 账户的 API 密钥。返回结果按从新到旧排序。

<Note>
  在 [Console → Personal Settings](https://www.cometapi.com/console/personal) 生成个人访问令牌，然后将其作为原始 `Authorization` 请求头值发送。不要添加 `Bearer` 前缀。
</Note>

## 分页

| Query parameter | Description                   |
| --------------- | ----------------------------- |
| `p`             | 页码。默认为 `1`。                   |
| `page_size`     | 每页条目数。大于 `100` 的值会被限制为 `100`。 |

## API 密钥状态

| Status | Meaning |
| ------ | ------- |
| `1`    | 已启用     |
| `2`    | 已禁用     |
| `3`    | 已过期     |
| `4`    | 已耗尽     |

## 返回字段

| Field                  | Type           | Description                                                                                                       |
| ---------------------- | -------------- | ----------------------------------------------------------------------------------------------------------------- |
| `id`                   | integer        | 数字形式的 API 密钥 ID。将此值用于 [获取单个 API 密钥](./get-api-key)、[更新 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/list-api-keys.openapi.json GET /api/token/
openapi: 3.1.0
info:
  title: List API Keys
  version: 1.0.0
servers:
  - url: https://api.cometapi.com
security:
  - accessTokenAuth: []
paths:
  /api/token/:
    get:
      summary: List API keys
      description: >-
        List API keys for the authenticated account. The newest keys are
        returned first.
      operationId: listApiKeys
      parameters:
        - name: p
          in: query
          required: false
          description: Page number to return. Defaults to `1`.
          schema:
            type: integer
            minimum: 1
            default: 1
        - name: page_size
          in: query
          required: false
          description: >-
            Number of keys per page. Values above `100` are capped at `100` by
            the backend.
          schema:
            type: integer
            minimum: 1
            maximum: 100
            default: 20
      responses:
        '200':
          description: Paginated API key list.
          content:
            application/json:
              schema:
                type: object
                required:
                  - success
                  - message
                  - data
                properties:
                  success:
                    type: boolean
                  message:
                    type: string
                  data:
                    type: object
                    required:
                      - page
                      - page_size
                      - total
                      - items
                    properties:
                      page:
                        type: integer
                      page_size:
                        type: integer
                      total:
                        type: integer
                      items:
                        type: array
                        items:
                          $ref: '#/components/schemas/ApiKey'
              examples:
                success:
                  summary: API key list
                  value:
                    success: true
                    message: ''
                    data:
                      page: 1
                      page_size: 20
                      total: 1
                      items:
                        - 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/?p=1&page_size=20" \
              -H "Authorization: your-access-token"
components:
  schemas:
    ApiKey:
      $ref: '#/components/schemas/ApiKeyObject'
    ApiKeyObject:
      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`.

````