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

# Billing & usage

> How usage is calculated and tracked across inference, fine-tuning, and the Agent.

# Billing & usage

Usage is metered by **tokens** and **cost**. This page explains how usage is calculated, where you can see it, and how it connects to your balance.

<Callout type="info" title="Wallet vs. Coding Plans">
  Most usage is deducted from your prepaid **wallet** in real time. If you subscribe to a **[Coding Plan](/plans/coding-plans)**, requests against your plan's included GLM models consume your **request quota** instead — your wallet is only charged for usage outside the plan (non-plan models, fine-tuning, embeddings). See [Deposit funds](/billing/deposit-funds) and [Balance and deductions](/billing/balance-and-deductions).
</Callout>

## How usage is calculated

| Workload                               | How it's metered                                                                         | Unit      |
| -------------------------------------- | ---------------------------------------------------------------------------------------- | --------- |
| **Inference** (`/v1/chat/completions`) | Input + output tokens per request                                                        | tokens    |
| **Embeddings** (`/v1/embeddings`)      | Input tokens per request (only RedPill embedding models, e.g. `qwen/qwen3-embedding-8b`) | tokens    |
| **Fine-tuning** (`/api/training`)      | Billed **per GPU hour** while the job runs (not while queued)                            | GPU hours |
| **Agent** (`/api/agent/v1/...`)        | Per request / per step, metered like inference (input + output tokens)                   | tokens    |

Rates are per model or per category; the platform applies its pricing and optional markup. The exact per-token rate isn't always exposed in the API, but the dashboard and usage endpoints show **aggregate cost** and token counts.

## Token accounting

Inference and Agent responses report a `usage` object (OpenAI-compatible):

```json theme={null}
{
  "usage": {
    "prompt_tokens": 12,
    "completion_tokens": 8,
    "total_tokens": 20
  }
}
```

| Field                        | What it counts                                                      |
| ---------------------------- | ------------------------------------------------------------------- |
| `prompt_tokens` (input)      | Tokens in the prompt or message list.                               |
| `completion_tokens` (output) | Tokens in the generated completion.                                 |
| `total_tokens`               | Input + output.                                                     |
| Cache read/write             | When supported and reported by the model; may be priced separately. |
| Reasoning                    | When supported (e.g. chain-of-thought); may be reported separately. |

This `usage` object is what is metered and deducted from your balance.

## Where you see usage

* **Dashboard** — The **Usage** or **Billing** section shows token counts, cost over time, and breakdowns by model or endpoint. Go to **Account & settings → Usage** in the dashboard (wallet balance and token usage over the last 30 days).
* **API** — Query usage programmatically:

```bash theme={null}
curl https://api.llmtune.io/api/usage/summary \
  -H "Authorization: Bearer sk_YOUR_API_KEY"
```

Returns your `balanceUsd` and daily token counts (`tokens30d`). To check Coding Plan quota usage specifically, see `GET /api/subscriptions/current`.

<Callout type="tip" title="Catch runaway spend">
  A sudden cost spike usually means a loop, a runaway batch, or a misconfigured `max_tokens`. Filter usage by model/endpoint in the dashboard, then check [audit logs](/guides/security-compliance#audit-logs) to trace the source.
</Callout>

## How usage connects to balance

1. You **top up** your wallet via the dashboard — see [Deposit funds](/billing/deposit-funds).
2. Each successful request **outside your Coding Plan quota** — inference on non-plan models, embeddings, fine-tuning, or the Agent — **deducts** from your wallet based on the usage above. Requests against your plan's included models consume quota instead.
3. If your wallet can't cover a non-quota request, the API returns **402 Payment Required**. Add funds and retry.

**Failed requests are not charged.** If a request errors (4xx/5xx), no tokens are billed — only successful completions are deducted. See [Balance and deductions](/billing/balance-and-deductions) for the full `402` response shape and how to handle it in code.

## Next

* [Deposit funds](/billing/deposit-funds) — How to add funds and the deposit flow.
* [Balance and deductions](/billing/balance-and-deductions) — Deduction model, the `402` response, and handling it in code.
* [Usage Metering](/core-concepts/usage-metering) — Metrics captured across products (inference, training, deployment).
* [API endpoints](/api/endpoints) — The endpoints that consume balance.
