> ## 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>
  **サードパーティ連携の場合:** API キー認証の `GET /credits/history/api` を利用してください。
</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 成功 (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 キー認証でクレジット取引履歴を返します。サードパーティ連携向けです。

### 認証

API キー認証が必要です。`Authorization` ヘッダーに API キーを付与します。

```
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>
