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

# 残高と利用状況を照会する

> CometAPI CLI または照会サービス API を使用して、アカウント残高、利用状況、キーごとのクォータ詳細を取得します。

CometAPI では、アカウント残高と利用状況を確認する方法として、**CometAPI CLI** と `query.cometapi.com` の **照会サービス API** の 2 つを提供しています。

Workspace を使用している場合は、[CometAPI Workspace でチームを管理する](/ja/workspace/overview)を参照して、共有 Organization Credits と請求ロールについて確認してください。

***

## CometAPI CLI

ターミナルから 1 つのコマンドで残高を確認できます。インストールについては、[CometAPI CLI の概要](/ja/libraries/cli/overview) を参照してください。

```bash theme={null}
cometapi balance
```

キーごとの詳細を表示するには、`--source token` を追加します。

```bash theme={null}
cometapi balance --source token
```

利用可能なすべてのオプションについては、[コマンドリファレンス](/ja/libraries/cli/commands) を参照してください。

***

## Query service API

`GET https://query.cometapi.com/user/quota`

アカウントレベルの残高、累積使用量、総リクエスト数、およびキーごとの quota 詳細を返します。このエンドポイントは `query.cometapi.com` 上の別個の query service を使用し、Bearer Token ではなく `key` クエリパラメータで認証します。

<Tip>
  残高照会には専用の API key を使用してください。公開範囲を制限したい場合は、Unlimited Quota を無効にし、ダッシュボードで許可されている最小の正のクレジット上限を設定してください。
</Tip>

### Request parameters

| Parameter    | Type   | Required | Description               |
| ------------ | ------ | -------- | ------------------------- |
| `key`        | string | Yes      | あなたの CometAPI API key     |
| `start_date` | string | No       | 日別内訳の開始日（`YYYY-MM-DD` 形式） |
| `end_date`   | string | No       | 日別内訳の終了日（`YYYY-MM-DD` 形式） |

`start_date` と `end_date` が指定されている場合、レスポンスには日ごとにキー別の使用量を分解した `daily_quota` フィールドが含まれます。

### Response fields

| Field                               | Type    | Description                                      |
| ----------------------------------- | ------- | ------------------------------------------------ |
| `username`                          | string  | ユーザー名                                            |
| `total_quota`                       | number  | 現在のアカウント残高（USD）                                  |
| `total_used_quota`                  | number  | 累積使用量（USD）                                       |
| `request_count`                     | integer | 総リクエスト数                                          |
| `keys`                              | array   | キーごとの quota 詳細                                   |
| `keys[].name`                       | string  | API key 名                                        |
| `keys[].remain_quota`               | number  | キーの残り quota。`-1` は無制限を意味します                      |
| `keys[].used_quota`                 | number  | キーの使用済み quota。`-1` は無制限を意味します                    |
| `daily_quota`                       | object  | 日別使用量の内訳（`start_date` と `end_date` が設定されている場合のみ） |
| `daily_quota[date]`                 | array   | その日付のキー別使用量エントリ                                  |
| `daily_quota[date][].token_name`    | string  | API key 名                                        |
| `daily_quota[date][].quota_used`    | number  | その日付におけるそのキーの使用量（USD）                            |
| `daily_quota[date][].request_count` | integer | その日付におけるそのキーのリクエスト数                              |

### Code examples

アカウント残高を照会するには:

<CodeGroup>
  ```bash curl theme={null}
  curl "https://query.cometapi.com/user/quota?key=$COMETAPI_KEY"
  ```

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

  resp = requests.get(
      "https://query.cometapi.com/user/quota",
      params={"key": os.environ["COMETAPI_KEY"]}
  )
  data = resp.json()
  print(f"Balance: ${data['total_quota']:.2f}")
  print(f"Used: ${data['total_used_quota']:.2f}")
  print(f"Requests: {data['request_count']}")
  ```

  ```javascript Node.js theme={null}
  const resp = await fetch(
    `https://query.cometapi.com/user/quota?key=${process.env.COMETAPI_KEY}`
  );
  const data = await resp.json();
  console.log(`Balance: $${data.total_quota.toFixed(2)}`);
  console.log(`Used: $${data.total_used_quota.toFixed(2)}`);
  console.log(`Requests: ${data.request_count}`);
  ```
</CodeGroup>

### Response example

```json theme={null}
{
  "username": "example_user",
  "total_quota": 2105.23,
  "total_used_quota": 21.07,
  "request_count": 1221,
  "keys": [
    {
      "name": "my-key",
      "remain_quota": 8.94,
      "used_quota": 2.10
    }
  ]
}
```

### Daily breakdown example

日付範囲の日別使用量を照会するには:

```bash theme={null}
curl "https://query.cometapi.com/user/quota?key=$COMETAPI_KEY&start_date=2026-04-13&end_date=2026-04-14"
```

レスポンスには、同じトップレベルフィールドに加えて `daily_quota` が含まれます:

```json theme={null}
{
  "username": "example_user",
  "total_quota": 2105.23,
  "total_used_quota": 21.07,
  "request_count": 1221,
  "daily_quota": {
    "2026-04-13T00:00:00Z": [
      {
        "token_name": "my-key",
        "quota_used": 4.27,
        "request_count": 59
      }
    ],
    "2026-04-14T00:00:00Z": [
      {
        "token_name": "my-key",
        "quota_used": 0.57,
        "request_count": 36
      }
    ]
  }
}
```
