> ## 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 API key hiện tại

> Sử dụng CometAPI GET /api/usage/token để truy xuất thông tin quota, mức sử dụng, thời hạn hết hạn và giới hạn model cho API key bearer.

Sử dụng endpoint này để kiểm tra API key CometAPI được dùng trong request. Endpoint này trả về các trường về mức sử dụng và quota cho bearer key, không phải danh sách tất cả key ở cấp tài khoản.

<Note>
  Endpoint này sử dụng một API key CometAPI: `Authorization: Bearer $COMETAPI_KEY`. Các endpoint quản lý API key sử dụng một personal access token riêng.
</Note>

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

| Field                  | Type    | Description                                                                                                                    |
| ---------------------- | ------- | ------------------------------------------------------------------------------------------------------------------------------ |
| `name`                 | string  | Tên hiển thị của API key.                                                                                                      |
| `total_granted`        | integer | Tổng quota được cấp cho key này theo đơn vị quota nội bộ của CometAPI.                                                         |
| `total_used`           | integer | Lượng quota đã được key này sử dụng theo đơn vị quota nội bộ của CometAPI.                                                     |
| `total_available`      | integer | Lượng quota còn lại khả dụng cho key này theo đơn vị quota nội bộ của CometAPI.                                                |
| `unlimited_quota`      | boolean | Key này có bỏ qua việc kiểm tra quota còn lại hay không.                                                                       |
| `model_limits`         | object  | Các giới hạn model cho key này, được lập chỉ mục theo model ID. Trống khi không cấu hình giới hạn model.                       |
| `model_limits_enabled` | boolean | Các giới hạn model có đang được áp dụng cho key này hay không.                                                                 |
| `expires_at`           | integer | Unix timestamp tính bằng giây cho biết thời điểm key hết hạn. `0` nghĩa là không có thời hạn hết hạn trong phản hồi usage này. |


## OpenAPI

````yaml api/openapi/api-keys/get-current-api-key.openapi.json GET /api/usage/token
openapi: 3.1.0
info:
  title: Get Current API Key
  version: 1.0.0
servers:
  - url: https://api.cometapi.com
security:
  - bearerAuth: []
paths:
  /api/usage/token:
    get:
      summary: Get current API key
      description: >-
        Retrieve usage, quota, expiration, and model-limit details for the
        CometAPI API key sent in the bearer Authorization header.
      operationId: getCurrentApiKey
      responses:
        '200':
          description: Current API key usage details.
          content:
            application/json:
              schema:
                type: object
                required:
                  - code
                  - message
                  - data
                properties:
                  code:
                    type: boolean
                    description: Whether the request succeeded.
                  message:
                    type: string
                    description: Status message.
                  data:
                    type: object
                    required:
                      - object
                      - name
                      - total_granted
                      - total_used
                      - total_available
                      - unlimited_quota
                      - model_limits
                      - model_limits_enabled
                      - expires_at
                    properties:
                      object:
                        type: string
                        description: Object type.
                        example: token_usage
                      name:
                        type: string
                        description: >-
                          Display name of the bearer API key used by the
                          request.
                        example: production
                      total_granted:
                        type: integer
                        description: >-
                          Total quota assigned to this key in CometAPI internal
                          quota units.
                        example: 150000
                      total_used:
                        type: integer
                        description: >-
                          Quota consumed by this key in CometAPI internal quota
                          units.
                        example: 50000
                      total_available:
                        type: integer
                        description: >-
                          Remaining quota available to this key in CometAPI
                          internal quota units.
                        example: 100000
                      unlimited_quota:
                        type: boolean
                        description: Whether the key bypasses remaining-quota checks.
                        example: false
                      model_limits:
                        type: object
                        description: >-
                          Model restrictions for this key, keyed by model ID.
                          Empty when no model limits are configured.
                        additionalProperties:
                          type: boolean
                        example: {}
                      model_limits_enabled:
                        type: boolean
                        description: Whether model restrictions are active for this key.
                        example: false
                      expires_at:
                        type: integer
                        description: >-
                          Unix timestamp in seconds when the key expires. `0`
                          means no expiration in this usage response.
                        example: 0
              examples:
                success:
                  summary: Current key usage
                  value:
                    code: true
                    message: ok
                    data:
                      object: token_usage
                      name: production
                      total_granted: 150000
                      total_used: 50000
                      total_available: 100000
                      unlimited_quota: false
                      model_limits:
                        gpt-4.1: true
                      model_limits_enabled: true
                      expires_at: 0
      x-codeSamples:
        - lang: curl
          label: cURL
          source: |-
            curl https://api.cometapi.com/api/usage/token \
              -H "Authorization: Bearer $COMETAPI_KEY"
components:
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      bearerFormat: CometAPI API key
      description: >-
        CometAPI API key used for model requests. Send it as `Authorization:
        Bearer $COMETAPI_KEY`.

````