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

# APIKey管理

> 無需登入官網，即可查詢 API Key 的到期情況，方便定時檢查和設定提醒。

## 套餐權限

| 套餐 | 可用 |
| - | :-: |
| 免費版 | ✅ |
| 基礎版 | ✅ |
| 專業版 | ✅ |
| 全量套餐（A 股、港股、美股） | ✅ |
| 企業版 | ✅ |

使用自己的 API Key 查詢帳戶名下各 Key 的到期時間和剩餘秒數，無需登入官網。

## 請求參數

此介面不需要查詢參數。

## 請求示例

```bash theme={null}
curl -H "X-API-Key: YOUR_API_KEY" \
  "https://api.tickdb.ai/v1/apikeys/subscriptions"
```

## 返回欄位說明

以下列出 `data` 中的欄位；外層 `code=0` 表示成功。

| 欄位 | 說明 |
| - | - |
| server\_time | 本次查詢的伺服器時間，包含時區的日期時間字串。 |
| total | 返回的 API Key 數量。 |
| api\_keys | 帳戶名下的 API Key 列表。 |
| └─ key\_prefix | API Key 前綴，用於辨認 Key；不是完整密鑰。 |
| └─ name | API Key 名稱。 |
| └─ plan | 該 Key 對應的方案識別碼。 |
| └─ status | Key 狀態：`active`（有效）、`expired`（已過期）、`suspended`（已暫停）、`revoked`（已撤銷）。 |
| └─ expires\_at | 到期時間；未設定到期時間時為 `null`。 |
| └─ remaining\_seconds | 距離到期的剩餘秒數；已到期時為 `0`，未設定到期時間時為 `null`。 |
| └─ created\_at | API Key 建立時間。 |


## OpenAPI

````yaml openapi.zh-Hant.yaml GET /v1/apikeys/subscriptions
openapi: 3.1.0
info:
  title: TickDB API
  description: TickDB 統一即時行情數據 API，提供 REST 和 WebSocket 接入。
  version: 1.0.3
  contact:
    email: support@tickdb.ai
servers:
  - url: https://api.tickdb.ai
    description: 正式環境
security:
  - ApiKeyAuth: []
paths:
  /v1/apikeys/subscriptions:
    get:
      tags:
        - account
      summary: APIKey管理
      description: 無需登入官網，即可查詢 API Key 的到期情況，方便定時檢查和設定提醒。
      operationId: getAPIKeyStatus
      responses:
        '200':
          $ref: '#/components/responses/APIKeyStatusResponse'
        default:
          $ref: '#/components/responses/ErrorResponse'
components:
  responses:
    APIKeyStatusResponse:
      description: APIKey管理回應。
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/APIKeyStatusEnvelope'
    ErrorResponse:
      description: >-
        錯誤回應。常見 HTTP 狀態包括
        400（參數錯誤）、401（驗證失敗）、403（權限或配額限制）、404（無符合條件的數據）、429（請求頻率限制）及 503（服務暫不可用）。
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorEnvelope'
          examples:
            missingAPIKey:
              summary: 缺少 API Key
              value:
                code: '1002'
                message: API key is required. Provide via X-API-Key header
                error: '1002'
            missingKind:
              summary: 缺少必填參數
              value:
                code: 40001
                message: kind is required
                data: null
            endpointForbidden:
              summary: API Key 無權存取此介面
              value:
                code: 3009
                message: This endpoint is not allowed for your API key
                data: null
            marketForbidden:
              summary: API Key 未開放該市場
              value:
                code: 3010
                message: Fundamentals market not allowed for your API key
                data:
                  market: US
            noAvailableSource:
              summary: 數據暫不可用
              value:
                code: 5003
                message: Data is temporarily unavailable
                data: null
            notFound:
              summary: 無符合條件的數據
              value:
                code: 40404
                message: shareholder detail not found
                data: null
            businessNoData:
              summary: 查詢條件沒有有效業務數據
              value:
                code: 40405
                message: valuation time series not found
                data: null
  schemas:
    APIKeyStatusEnvelope:
      allOf:
        - $ref: '#/components/schemas/SuccessEnvelope'
        - type: object
          required:
            - data
          properties:
            message:
              type: string
              description: 響應消息。
            data:
              $ref: '#/components/schemas/APIKeyStatusData'
    ErrorEnvelope:
      type: object
      required:
        - code
        - message
      properties:
        code:
          description: TickDB API 業務錯誤碼；可能是整數或字串，客戶端應先轉為字串再比較。
          oneOf:
            - type: integer
            - type: string
        message:
          type: string
          description: 錯誤說明。
        error:
          type: string
          description: 相容錯誤標識；僅部分錯誤回應返回。
        data:
          description: 可選的錯誤上下文；可能是 null、物件或陣列。
          oneOf:
            - type: 'null'
            - type: object
              additionalProperties: true
            - type: array
              items: {}
    SuccessEnvelope:
      type: object
      required:
        - code
        - data
      properties:
        code:
          type: integer
          const: 0
          description: 業務狀態碼，成功為 `0`。
    APIKeyStatusData:
      type: object
      required:
        - server_time
        - total
        - api_keys
      properties:
        server_time:
          type: string
          format: date-time
          description: 本次查詢的伺服器時間，包含時區的日期時間字串。
        total:
          type: integer
          minimum: 0
          description: 返回的 API Key 數量。
        api_keys:
          type: array
          description: 帳戶名下的 API Key 列表。
          items:
            $ref: '#/components/schemas/APIKeyStatusItem'
      additionalProperties: false
    APIKeyStatusItem:
      type: object
      required:
        - key_prefix
        - name
        - plan
        - status
        - expires_at
        - remaining_seconds
        - created_at
      properties:
        key_prefix:
          type: string
          description: API Key 前綴，用於辨認 Key；不是完整密鑰。
        name:
          type: string
          description: API Key 名稱。
        plan:
          type: string
          description: 該 Key 對應的方案識別碼。
        status:
          type: string
          enum:
            - active
            - expired
            - suspended
            - revoked
          description: Key 狀態：`active`（有效）、`expired`（已過期）、`suspended`（已暫停）、`revoked`（已撤銷）。
        expires_at:
          type:
            - string
            - 'null'
          format: date-time
          description: 到期時間；未設定到期時間時為 `null`。
        remaining_seconds:
          type:
            - integer
            - 'null'
          minimum: 0
          description: 距離到期的剩餘秒數；已到期時為 `0`，未設定到期時間時為 `null`。
        created_at:
          type: string
          format: date-time
          description: API Key 建立時間。
      additionalProperties: false
  securitySchemes:
    ApiKeyAuth:
      type: apiKey
      in: header
      name: X-API-Key

````

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.