# Account & Wallet API

This section covers both **direct quota queries using an API Key (`sk-xxx`) without logging in** and **managing your personal account and wallet using a console JWT token**.

---

## 1. Direct Balance Query Using API Key (No Login Required; Ideal for Client Runtime)

Clients or backend services do not need to log in for a JWT at runtime—simply pass the API key (`Authorization: Bearer sk-your_token`) in the request header to query token quota and total account balance in real time.

### 1. Query Current Token Quota (Token Balance)
Query the remaining available sub-quota and used quota of a specific API Key (Token).
* **Path**: `/v1/balance`
* **Method**: `GET`
* **Header**: `Authorization: Bearer sk-your_token`
* **Call Example (Curl)**:
```bash
curl -X GET https://www.tokenpad.ai/v1/balance \
  -H "Authorization: Bearer sk-your_token"
```
* **Response Body Example**:
```json
{
  "success": true,
  "remain_balance": 985.42,
  "used_balance": 14.58,
  "unlimited_quota": false
}
```
* **Field Descriptions**:
  * `remain_balance`: Remaining available quota of the current token; returns `-1` when the token is configured with **unlimited quota**.
  * `used_balance`: Cumulative quota already consumed by the current token.
  * `unlimited_quota`: Whether the token has unlimited quota (`true` for unlimited, `false` for a fixed quota cap).

### 2. Query User Total Account Balance (User Balance)
Retrieve the overall available balance of the user account that owns the current API key (including recharge balance, gift balance, and available credit limit, rather than an individual token's sub-quota limit).
* **Path**: `/v1/user/balance`
* **Method**: `GET`
* **Header**: `Authorization: Bearer sk-your_token`
* **Call Example (Curl)**:
```bash
curl -X GET https://www.tokenpad.ai/v1/user/balance \
  -H "Authorization: Bearer sk-your_token"
```
* **Response Body Example**:
```json
{
  "success": true,
  "remain_balance": 500.00,
  "used_balance": 24.50,
  "unlimited_quota": false
}
```

---

## 2. Console Account & Wallet Management (Requires JWT Login Auth)

The following endpoints require a login JWT token (`Authorization: Bearer <JWT>`) in the request header to query profile details, wallet statistics, recharge history, and transfer affiliate commissions.

### 1. Get User Profile (Profile)
* **Path**: `/api/v1/user/profile`
* **Method**: `GET`
* **Response Body Example**:
```json
{
  "id": "1",
  "username": "user1",
  "email": "user@example.com",
  "mobile": "13800000000",
  "role": "user",
  "user_group": "default",
  "is_active": 1,
  "created_at": "2026-06-01T12:00:00Z"
}
```

### 2. Get Wallet Stats & Balance (Wallet)
* **Path**: `/api/v1/user/wallet`
* **Method**: `GET`
* **Response Body Example**:
```json
{
  "balance": 500.00,
  "spent": 24.50,
  "affiliate_commission": 15.00,
  "user_level": "VIP 1",
  "discount_rate": 0.95
}
```

### 3. Get Recharge History
* **Path**: `/api/v1/user/recharge_records`
* **Method**: `GET`
* **Response Body Example**:
```json
{
  "data": [
    {
      "id": "1001",
      "amount": 100.00,
      "method": "wechat",
      "status": "success",
      "created_at": "2026-06-15T09:30:00Z"
    }
  ],
  "total": 1
}
```

### 4. Transfer Affiliate Commissions
Transfer affiliate commissions earned from referral registrations/spending into your account balance for API consumption.
* **Path**: `/api/v1/user/affiliate/transfer`
* **Request Method**: `POST`
* **Request Body Example**:
```json
{
  "amount": 10.00
}
```
* **Response Body Example**:
```json
{
  "message": "Commission transferred successfully",
  "new_balance": 510.00,
  "remaining_commission": 5.00
}
```