# Tokens & Usage Logs API

Manage API keys (API Keys) under your account with full CRUD operations, and query LLM call logs or async task execution status.

### 1. List Tokens
* **Path**: `/api/v1/tokens`
* **Method**: `GET`
* **Response Body Example**:
```json
{
  "data": [
    {
      "id": 5,
      "name": "Test Key",
      "kid": "usr123987",
      "quota_limit": 1000.0,
      "used_quota": 5.23,
      "is_active": 1,
      "created_at": "2026-06-20T10:00:00Z"
    }
  ],
  "total": 1
}
```

### 2. Create API Token
* **Path**: `/api/v1/tokens`
* **Request Method**: `POST`
* **Request Body Parameters**:
  * `name`: Token name (max 24 characters)
  * `quota_limit`: Quota limit (optional; empty means unlimited)
  * `allowed_models`: List of allowed models (optional, e.g., `["gpt-4o"]`)
  * `allowed_ips`: Bound whitelist IPs (optional, comma-separated)
  * `rps_limit` / `rpm_limit`: Requests per second / minute rate limits (optional)
* **Request Body Example**:
```json
{
  "name": "Image Gen Key",
  "quota_limit": 500.0,
  "allowed_models": ["gpt-4o", "claude-3-5-sonnet-20241022"],
  "allowed_ips": "192.168.1.1,10.0.0.1",
  "rps_limit": 10,
  "rpm_limit": 100
}
```
* **Response Body Example**:
```json
{
  "id": 6,
  "name": "Image Gen Key",
  "token_key": "sk-ProjX82...",
  "quota_limit": 500.0,
  "is_active": 1
}
```
*Note: The full plaintext key (`token_key`) of a new token is returned only once upon successful creation.*

### 3. Reveal Token Secret Key
* **Path**: `/api/v1/tokens/{id}/reveal`
* **Request Method**: `POST`
* **Response Body Example**:
```json
{
  "token_key": "sk-your_full_api_key_value_here"
}
```

### 4. Delete API Token
* **Path**: `/api/v1/tokens/{id}`
* **Method**: `DELETE`

### 5. Query LLM Usage Logs
* **Path**: `/api/v1/logs`
* **Method**: `GET`
* **Common Query Parameters**: `page`, `per_page`, `model`, `status` (`success`/`fail`), `start_date`, `end_date`
* **Response Body Example**:
```json
{
  "data": [
    {
      "log_id": "log_xyz123",
      "model": "gpt-4o",
      "prompt_tokens": 15,
      "completion_tokens": 20,
      "cost": 0.0007,
      "status_code": 200,
      "created_at": "2026-06-21T15:20:00Z"
    }
  ],
  "total": 1,
  "total_cost": 0.0007,
  "success_count": 1,
  "fail_count": 0
}
```

### 6. Query Async Task Logs (Video / Enhancement, etc.)
* **Path**: `/api/v1/task_logs`
* **Method**: `GET`
* **Endpoint Actions**: Call `POST /api/v1/task_logs/{log_id}/sync` to manually sync task status, or `POST /api/v1/task_logs/{log_id}/cancel` to cancel an in-progress async task.