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

# Balance and deductions

> How balance works, what gets deducted, and what happens when it runs out.

# Balance and deductions

LLMTune uses a **prepaid balance** (your "wallet"), measured in **USD**. You add funds up front, and usage **outside your Coding Plan quota** — inference on non-plan models, embeddings, fine-tuning, and Agent requests — is deducted from your wallet in real time. There are no end-of-cycle invoices; you only pay for what you use.

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

<Callout type="info" title="Prepaid, not postpaid">
  Because billing is prepaid, a request only runs if your balance can cover it. If it can't, you get a **402 Payment Required** *instead* of the response — see [What happens when balance runs out](#what-happens-when-balance-runs-out).
</Callout>

## How balance is used

| Workload                               | How it charges                                              |
| -------------------------------------- | ----------------------------------------------------------- |
| **Inference** (`/v1/chat/completions`) | Per request, based on input + output tokens.                |
| **Embeddings** (`/v1/embeddings`)      | Per request, based on input tokens.                         |
| **Fine-tuning** (`/api/training`)      | Per GPU hour, billed while the job runs (not while queued). |
| **Agent** (`/api/agent/v1/...`)        | Per request / per step, like inference.                     |

To add funds, see [Deposit funds](/billing/deposit-funds). To track what's been spent, see [Billing & usage](/billing/usage).

## How deductions work

1. When you call inference, embeddings, or the Agent, the platform:
   * Validates your API key.
   * Checks that your balance is sufficient (using an estimate or actual cost).
   * **If sufficient** — runs the request, computes usage (tokens), and deducts the cost from your balance.
   * **If insufficient** — returns **402 Payment Required** and does **not** run the request or deduct anything.

2. For **fine-tuning**, the job is billed per GPU hour while it runs. Insufficient balance can prevent the job from starting or cause it to fail — so fund the account before launching large jobs.

3. **Failed requests are not charged.** If a request errors (4xx/5xx), no tokens are billed. Only successful completions are deducted.

<Callout type="warning" title="Balance required for everything outside a plan">
  Every request **outside your Coding Plan quota** — including free / **Confidential** (own-your-data) models, fine-tuning, embeddings, and non-plan models — is checked against your wallet balance first. A `$0.00` balance returns `402` regardless of model tier. Requests against your plan's included models consume quota, not wallet. See [Coding Plans](/plans/coding-plans).
</Callout>

## What happens when balance runs out

When your balance can't cover a request, the API returns **402 Payment Required** with this body:

```json theme={null}
{
  "error": "Insufficient balance",
  "message": "Insufficient balance. Required: $0.0012, Available: $0.0000"
}
```

* **Meaning** — Your balance is too low for this request (or its estimated cost).
* **What to do** — Add funds in the dashboard at [Deposit funds](/billing/deposit-funds), then retry. In your app, surface a clear message (e.g. "Add funds") and link to billing.

### Handling 402 in code

Treat `402` as a billing issue, not a transient failure. Don't retry the same request in a loop — it will keep failing until the balance is topped up.

```python theme={null}
from openai import OpenAI, APIStatusError

client = OpenAI(base_url="https://api.llmtune.io/v1", api_key="sk_YOUR_API_KEY")

try:
    response = client.chat.completions.create(
        model="z-ai/GLM-5.2",
        messages=[{"role": "user", "content": "Hello"}],
    )
except APIStatusError as e:
    if e.status_code == 402:
        # Stop and ask the user to add funds — don't auto-retry.
        print("Balance too low. Please add funds at https://llmtune.io/billing.")
    else:
        raise
```

## Best practices

* **Monitor balance** — Track spend on the [Usage](/billing/usage) dashboard and top up before it hits zero.
* **Handle 402 explicitly** — Catch it in code, prompt the user to add funds, and do **not** retry until balance is updated.
* **Estimate before batch** — For large batch or fine-tuning jobs, check balance first so you don't start work that will fail mid-way.
* **Fund before fine-tuning** — Training is billed per GPU hour; ensure enough balance for the whole run.
* **Watch for unexpected drain** — A sudden balance drop often means a loop or runaway job. Check audit logs and usage by model/endpoint.

## Next

* [Deposit funds](/billing/deposit-funds) — How to add funds and the deposit flow.
* [Billing & usage](/billing/usage) — How token usage and cost are calculated and tracked.
* [API endpoints](/api/endpoints) — The endpoints that consume balance.
