> ## 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>
  **サードパーティ連携の場合:** API キー認証の `GET /credits/balance/api` を利用してください。
</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 成功 (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 未認証 (401) theme={null}
  {
    "message": "Unauthorized"
  }
  ```
</ResponseExample>

***

## GET /credits/balance/api

API キー認証でユーザーの現在のクレジット残高を返します。サードパーティ連携や外部アプリ向けです。

### 認証

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

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