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

# 查询积分余额

> 获取当前用户的积分余额与使用统计。

## GET /credits/balance

返回当前认证用户的可用积分与使用统计。需要基于会话的 JWT 访问令牌鉴权。

<Note>
  \*\*第三方集成：\*\*请改用 `GET /credits/balance/api` 并以 API Key 鉴权。
</Note>

### 响应

<ResponseField name="balance" type="number">
  当前可用积分余额。
</ResponseField>

<ResponseField name="totalPurchased" type="number">
  账户历史上累计购买的积分。
</ResponseField>

<ResponseField name="totalUsed" type="number">
  账户历史上累计消耗的积分。
</ResponseField>

<ResponseField name="recentTransactions" type="array">
  最近的积分流水。

  <Expandable title="transaction 字段">
    <ResponseField name="id" type="string">
      流水 ID。
    </ResponseField>

    <ResponseField name="type" type="string">
      类型：`purchase`、`usage` 或 `refund`。
    </ResponseField>

    <ResponseField name="amount" type="number">
      积分变动（购买为正，消耗为负）。
    </ResponseField>

    <ResponseField name="description" type="string">
      可读说明。
    </ResponseField>

    <ResponseField name="createdAt" type="string">
      时间（ISO 8601）。
    </ResponseField>
  </Expandable>
</ResponseField>

<RequestExample>
  ```bash cURL theme={null}
  curl -X GET https://api.llmgenerator.com/api/v1/credits/balance \
    -H "Authorization: Bearer YOUR_ACCESS_TOKEN"
  ```

  ```javascript Node.js theme={null}
  const response = await fetch('https://api.llmgenerator.com/api/v1/credits/balance', {
    headers: {
      'Authorization': 'Bearer YOUR_ACCESS_TOKEN'
    }
  });

  const data = await response.json();
  ```

  ```python Python theme={null}
  import requests

  response = requests.get(
      'https://api.llmgenerator.com/api/v1/credits/balance',
      headers={'Authorization': 'Bearer YOUR_ACCESS_TOKEN'}
  )

  data = response.json()
  ```
</RequestExample>

<ResponseExample>
  ```json Success (200) theme={null}
  {
    "balance": 450,
    "totalPurchased": 1000,
    "totalUsed": 550,
    "recentTransactions": [
      {
        "id": "txn_abc123",
        "type": "purchase",
        "amount": 500,
        "description": "Purchased Pro Pack",
        "createdAt": "2026-01-15T10:00:00Z"
      },
      {
        "id": "txn_def456",
        "type": "usage",
        "amount": -50,
        "description": "API LLMs.txt generation (enhanced) for example.com (25 URLs)",
        "createdAt": "2026-01-20T14:30:00Z"
      }
    ]
  }
  ```

  ```json Unauthorized (401) theme={null}
  {
    "message": "Unauthorized"
  }
  ```
</ResponseExample>

***

## GET /credits/balance/api

使用 API Key 返回当前用户的积分余额，适合第三方集成与外部应用。

### 认证

需要 API Key。在 `Authorization` 请求头中携带：

```
Authorization: Bearer llmgen_your_api_key_here
```

### 响应

与上文 `/credits/balance` 相同。

<RequestExample>
  ```bash cURL theme={null}
  curl -X GET https://api.llmgenerator.com/api/v1/credits/balance/api \
    -H "Authorization: Bearer llmgen_your_api_key_here"
  ```

  ```javascript Node.js theme={null}
  const response = await fetch('https://api.llmgenerator.com/api/v1/credits/balance/api', {
    headers: {
      'Authorization': 'Bearer llmgen_your_api_key_here'
    }
  });

  const data = await response.json();
  ```

  ```python Python theme={null}
  import requests

  response = requests.get(
      'https://api.llmgenerator.com/api/v1/credits/balance/api',
      headers={'Authorization': 'Bearer llmgen_your_api_key_here'}
  )

  data = response.json()
  ```
</RequestExample>
