> ## 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.

# Query balance and usage

> Use the CometAPI CLI or query service API to retrieve account balance, usage, and per-key quota details.

CometAPI provides two ways to check account balance and usage: the **CometAPI CLI** and the **query service API** at `query.cometapi.com`.

If you use a Workspace, see [Manage a team with CometAPI Workspace](/workspace/overview) to understand shared Organization Credits and billing roles.

***

## CometAPI CLI

Check your balance from the terminal with one command. See [CometAPI CLI overview](/libraries/cli/overview) for installation.

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

Add `--source token` for per-key details:

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

See the [commands reference](/libraries/cli/commands) for all available options.

***

## Query service API

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

Returns account-level balance, cumulative usage, total request count, and per-key quota details. This endpoint uses a separate query service at `query.cometapi.com` and authenticates via the `key` query parameter rather than a Bearer Token.

<Tip>
  Use a dedicated API key for balance queries. If you want to limit exposure, disable Unlimited Quota and set the smallest positive credit limit allowed by the dashboard.
</Tip>

### Request parameters

| Parameter    | Type   | Required | Description                                          |
| ------------ | ------ | -------- | ---------------------------------------------------- |
| `key`        | string | Yes      | Your CometAPI API key                                |
| `start_date` | string | No       | Start date for daily breakdown (`YYYY-MM-DD` format) |
| `end_date`   | string | No       | End date for daily breakdown (`YYYY-MM-DD` format)   |

When `start_date` and `end_date` are provided, the response includes a `daily_quota` field with per-key usage broken down by day.

### Response fields

| Field                               | Type    | Description                                                           |
| ----------------------------------- | ------- | --------------------------------------------------------------------- |
| `username`                          | string  | Username                                                              |
| `total_quota`                       | number  | Current account balance (USD)                                         |
| `total_used_quota`                  | number  | Cumulative usage (USD)                                                |
| `request_count`                     | integer | Total request count                                                   |
| `keys`                              | array   | Per-key quota details                                                 |
| `keys[].name`                       | string  | API key name                                                          |
| `keys[].remain_quota`               | number  | Key remaining quota; `-1` means unlimited                             |
| `keys[].used_quota`                 | number  | Key used quota; `-1` means unlimited                                  |
| `daily_quota`                       | object  | Daily usage breakdown (only when `start_date` and `end_date` are set) |
| `daily_quota[date]`                 | array   | Per-key usage entries for that date                                   |
| `daily_quota[date][].token_name`    | string  | API key name                                                          |
| `daily_quota[date][].quota_used`    | number  | Usage for that key on that date (USD)                                 |
| `daily_quota[date][].request_count` | integer | Request count for that key on that date                               |

### Code examples

Query account balance:

<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

Query daily usage for a date range:

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

The response includes the same top-level fields plus `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
      }
    ]
  }
}
```
