> ## 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/history

返回当前认证用户的积分流水，包含购买、消耗与退款等。需要 JWT 访问令牌（会话鉴权）。

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

### 查询参数

<ParamField query="limit" type="number" default="20">
  返回条数（最大 100）。
</ParamField>

<ParamField query="offset" type="number" default="0">
  分页偏移（跳过的条数）。
</ParamField>

<ParamField query="type" type="string">
  按类型筛选：`purchase`、`usage` 或 `refund`。
</ParamField>

### 响应

<ResponseField name="transactions" type="array">
  流水对象数组。

  <Expandable title="transaction 字段">
    <ResponseField name="id" type="string">
      流水唯一标识。
    </ResponseField>

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

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

    <ResponseField name="description" type="string">
      说明文案。
    </ResponseField>

    <ResponseField name="siteId" type="string">
      关联站点 ID（消耗类流水）。
    </ResponseField>

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

<ResponseField name="total" type="number">
  符合条件的流水总数。
</ResponseField>

<ResponseField name="hasMore" type="boolean">
  是否还有更多记录。
</ResponseField>

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

  ```javascript Node.js theme={null}
  const response = await fetch(
    'https://api.llmgenerator.com/api/v1/credits/history?limit=10&type=usage',
    {
      headers: { 'Authorization': 'Bearer YOUR_ACCESS_TOKEN' }
    }
  );

  const history = await response.json();
  ```
</RequestExample>

<ResponseExample>
  ```json Success (200) theme={null}
  {
    "transactions": [
      {
        "id": "txn_abc123",
        "type": "purchase",
        "amount": 500,
        "description": "Purchased Professional Pack",
        "siteId": null,
        "createdAt": "2026-01-15T10:00:00.000Z"
      },
      {
        "id": "txn_def456",
        "type": "usage",
        "amount": -50,
        "description": "llms.txt generation for example.com (enhanced)",
        "siteId": "550e8400-e29b-41d4-a716-446655440000",
        "createdAt": "2026-01-20T14:30:00.000Z"
      },
      {
        "id": "txn_ghi789",
        "type": "usage",
        "amount": -25,
        "description": "llms.txt generation for another-site.com (simple)",
        "siteId": "660e8400-e29b-41d4-a716-446655440001",
        "createdAt": "2026-01-22T09:15:00.000Z"
      }
    ],
    "total": 47,
    "hasMore": true
  }
  ```
</ResponseExample>

***

## GET /credits/history/api

使用 API Key 返回积分流水，适合第三方集成。

### 认证

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

```
Authorization: Bearer llmgen_your_api_key_here
```

### 查询参数

与 `/credits/history` 相同。

### 响应

与 `/credits/history` 相同。

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

  ```javascript Node.js theme={null}
  const response = await fetch(
    'https://api.llmgenerator.com/api/v1/credits/history/api?limit=10&type=usage',
    {
      headers: { 'Authorization': 'Bearer llmgen_your_api_key_here' }
    }
  );

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

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

  response = requests.get(
      'https://api.llmgenerator.com/api/v1/credits/history/api',
      headers={'Authorization': 'Bearer llmgen_your_api_key_here'},
      params={'limit': 10, 'type': 'usage'}
  )

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