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

# Lấy một API key

> Sử dụng CometAPI GET /api/token/{id} để lấy một bản ghi API key theo ID cho tài khoản đã được xác thực.

Sử dụng endpoint này để lấy một bản ghi API key theo ID.

<Note>
  Tạo personal access token tại [Console → Personal Settings](https://www.cometapi.com/console/personal), sau đó gửi token này làm giá trị thô của header `Authorization`. Không thêm tiền tố `Bearer`.
</Note>

Tham số đường dẫn `id` là ID khóa dạng số được trả về bởi [Liệt kê API key](./list-api-keys).

## Trạng thái API key

| Status | Meaning     |
| ------ | ----------- |
| `1`    | Đã bật      |
| `2`    | Đã tắt      |
| `3`    | Đã hết hạn  |
| `4`    | Đã dùng hết |

## Các trường được trả về

| Field                  | Type           | Description                                                                                                                                                                                                           |
| ---------------------- | -------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `id`                   | integer        | ID API key dạng số. Sử dụng giá trị này với [Cập nhật một API key](./update-api-key) và [Xóa một API key](./delete-api-key).                                                                                          |
| `key`                  | string         | Giá trị API key được trả về bởi management API. Hãy xem đây là một bí mật và sử dụng nó dưới dạng `Authorization: Bearer $COMETAPI_KEY` cho các yêu cầu model.                                                        |
| `status`               | integer        | Trạng thái hoạt động. Chỉ `1` có nghĩa là khóa được bật cho các yêu cầu model.                                                                                                                                        |
| `name`                 | string         | Tên hiển thị dễ đọc cho người dùng của khóa.                                                                                                                                                                          |
| `created_time`         | integer        | Unix timestamp tính bằng giây tại thời điểm khóa được tạo.                                                                                                                                                            |
| `accessed_time`        | integer        | Unix timestamp tính bằng giây tại thời điểm khóa được sử dụng lần gần nhất.                                                                                                                                           |
| `expired_time`         | integer        | Unix timestamp tính bằng giây tại thời điểm khóa hết hạn. `-1` nghĩa là không hết hạn.                                                                                                                                |
| `remain_quota`         | integer        | Hạn mức còn lại theo đơn vị hạn mức nội bộ của CometAPI.                                                                                                                                                              |
| `used_quota`           | integer        | Hạn mức đã được tiêu thụ bởi khóa này theo đơn vị hạn mức nội bộ của CometAPI.                                                                                                                                        |
| `unlimited_quota`      | boolean        | Khóa có bỏ qua việc kiểm tra hạn mức còn lại hay không.                                                                                                                                                               |
| `model_limits_enabled` | boolean        | Các giới hạn model có đang được áp dụng cho khóa này hay không.                                                                                                                                                       |
| `model_limits`         | string         | Danh sách model ID được phép dùng bởi khóa này, phân tách bằng dấu phẩy, khi `model_limits_enabled` là `true`. Để trống nghĩa là không có danh sách model nào được cấu hình.                                          |
| `allow_ips`            | string or null | Danh sách IP được phép dưới dạng một chuỗi phân tách bằng ký tự xuống dòng. Mỗi mục có thể là một địa chỉ IPv4 đơn lẻ, địa chỉ IPv6 đơn lẻ, IPv4 CIDR hoặc IPv6 CIDR. `null` hoặc `""` nghĩa là không có giới hạn IP. |
| `group`                | string         | Giới hạn nhóm tài khoản. Để trống nghĩa là không có giới hạn nhóm rõ ràng.                                                                                                                                            |
| `cross_group_retry`    | boolean        | Có bật thử lại liên nhóm để định tuyến nhóm tự động hay không.                                                                                                                                                        |


## 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`.

````