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

# CreditBalance

> One credit balance: credits available, the time of the reading, and where the credits come from.

`CreditBalance` shows how many credits a customer has in one credit system, and the grants and top-ups they come from. From React `0.11.0`.

**When to use**

* Next to an AI or credit-metered feature, so customers see what is left.
* The credits section of your billing settings, with [`CreditHistory`](/sdks/react/components/credit-history) below it.
* Any place that shows what remains of each grant or top-up and when it expires.

**Light**

![CreditBalance with 1,240 AI credits from a plan grant and a top-up, light theme](https://mintcdn.com/nozle-d78f01d8/Ae2cAgwEfN_SPqzG/images/react/components/credit-balance/light.png?fit=max\&auto=format\&n=Ae2cAgwEfN_SPqzG\&q=85\&s=a0f6be69e735b01f3901fda131e932f5)

**Dark**

![CreditBalance with 1,240 AI credits from a plan grant and a top-up, dark theme](https://mintcdn.com/nozle-d78f01d8/Ae2cAgwEfN_SPqzG/images/react/components/credit-balance/dark.png?fit=max\&auto=format\&n=Ae2cAgwEfN_SPqzG\&q=85\&s=c7af60ef4a728ad65f961680c37f75bb)

**Minimal**

![CreditBalance with 1,240 AI credits from a plan grant and a top-up, minimal theme](https://mintcdn.com/nozle-d78f01d8/Ae2cAgwEfN_SPqzG/images/react/components/credit-balance/minimal.png?fit=max\&auto=format\&n=Ae2cAgwEfN_SPqzG\&q=85\&s=3edccade9bf9943288fc5efab1b6a6c6)

**Neobrutal**

![CreditBalance with 1,240 AI credits from a plan grant and a top-up, neobrutal theme](https://mintcdn.com/nozle-d78f01d8/Ae2cAgwEfN_SPqzG/images/react/components/credit-balance/neobrutal.png?fit=max\&auto=format\&n=Ae2cAgwEfN_SPqzG\&q=85\&s=3eecf4794e4d1dfd27d1619b21d53d2a)

**Nozle**

![CreditBalance with 1,240 AI credits from a plan grant and a top-up, nozle theme](https://mintcdn.com/nozle-d78f01d8/Ae2cAgwEfN_SPqzG/images/react/components/credit-balance/nozle.png?fit=max\&auto=format\&n=Ae2cAgwEfN_SPqzG\&q=85\&s=8783c3c38f929e3543b20a6439d6ecd3)

**Nozle Dark**

![CreditBalance with 1,240 AI credits from a plan grant and a top-up, nozleDark theme](https://mintcdn.com/nozle-d78f01d8/Ae2cAgwEfN_SPqzG/images/react/components/credit-balance/nozle-dark.png?fit=max\&auto=format\&n=Ae2cAgwEfN_SPqzG\&q=85\&s=cce9f260f280299c98a6b04e49f100fa)

## Importing CreditBalance

```tsx theme={null}
import {
  CreditBalance,
  useCreditBalance,
  type CreditBalanceData,
  type CreditBalanceSource,
} from '@nozle-js/react'
```

## Rendering CreditBalance

Inside a `BillingProvider` with `billingEndpoint`, read the balance with `useCreditBalance` and pass it in:

```tsx app/billing/credits/page.tsx theme={null}
'use client'
import { BillingProvider } from '@nozle-js/react'

function AiCredits() {
  const { data, isPending, error } = useCreditBalance('ai_credits')
  return <CreditBalance balance={data} isLoading={isPending} error={error} />
}

export default function CreditsPage() {
  return (
    <BillingProvider publishableKey="pk_nozle_..." billingEndpoint="/api/nozle">
      <AiCredits />
    </BillingProvider>
  )
}
```

The card shows the available credits with the unit name, singular for exactly 1 ("1 credit available", "1,240 credits available"), and "As of \<date>" for the time of the reading. Below it, one line per source shows what remains and when it expires.

## Data

`balance` is a `CreditBalanceData`. Credit amounts are decimal strings.

```tsx theme={null}
const balance: CreditBalanceData = {
  credit_system_name: 'AI credits',
  unit_name: 'credit',
  available: '1240',
  as_of: '2026-10-16T09:00:00Z',
  sources: [
    { id: 'grant_1', type: 'subscription_grant', remaining: '500', expires_at: '2026-11-01T00:00:00Z' },
    { id: 'topup_1', type: 'top_up', remaining: '740', expires_at: null },
  ],
}

export function Credits() {
  return <CreditBalance balance={balance} />
}
```

### Live data

Inside a `BillingProvider` with `billingEndpoint`, [`useCreditBalance(creditSystemCode?)`](/sdks/react/hooks#the-hooks) returns one balance of the signed-in customer: the given credit system, else the first one with credits, else the first one.

```tsx theme={null}
export function AiCredits() {
  const { data, isPending, error } = useCreditBalance('ai_credits')
  return <CreditBalance balance={data} isLoading={isPending} error={error} />
}
```

Without the hooks, pass one entry of the SDK's `credits.balance` result, read on your backend.

### Source types

Each source's `type` sets its label. A source type the component does not know shows as sent. Sources whose `remaining` is `"0"` are hidden.

| `type` | Label |
| - | - |
| `subscription_grant` | Plan grant |
| `top_up` | Top-up |
| `manual_grant` | Granted |
| `adjustment` | Adjustment |
| `allocated_top_up` | Allocated top-up |

## Examples

### Loading, empty and error

`isLoading` shows a loading placeholder, no `balance` shows `emptyMessage`, and `error` shows the message as an alert.

![CreditBalance loading placeholder, No credit balance yet message, and an error message, light theme](https://mintcdn.com/nozle-d78f01d8/Ae2cAgwEfN_SPqzG/images/react/components/credit-balance-states/light.png?fit=max\&auto=format\&n=Ae2cAgwEfN_SPqzG\&q=85\&s=1c66e725ef35508f8c45429c8530c2af)

```tsx theme={null}
export function BalanceStates() {
  return (
    <>
      <CreditBalance isLoading />
      <CreditBalance balance={null} />
      <CreditBalance error="Credits could not be loaded." />
    </>
  )
}
```

## API reference

**balance** `CreditBalanceData | null`

`null` or no value shows the empty message.

**properties**

**credit\_system\_name** `string` *required*

Heading of the card.

**unit\_name** `string` *required*

Singular unit name, for example `credit`. An `s` is added unless `available` is exactly 1.

**available** `string` *required*

Credits available, as a decimal string.

**as\_of** `string` *required*

Time of the reading, shown as "As of \<date>".

**sources** `CreditBalanceSource[]`

Where the credits come from: `id`, `type`, `remaining` and `expires_at`. See [Source types](#source-types).

**isLoading** `boolean` (default: false)

Shows a loading placeholder.

**error** `Error | string | null`

Shows the message as an alert. Defaults to `null`.

**emptyMessage** `string` (default: No credit balance yet.)

Shown when there is no balance.

**appearance** `Appearance`

Theme, variables and element overrides. Defaults to the provider's. See [Appearance](/sdks/react/styling).

Dates show in `en-US` ("Oct 16, 2026").

### States

| State | What shows |
| - | - |
| `isLoading` | A skeleton placeholder with `role="status"`. |
| `error` set | The message in a `role="alert"` card, in the danger text colour. |
| No `balance` | `emptyMessage`. |

### Appearance

> **Element keys**
>
> `creditBalance` (root), `creditBalance__amount` (the large number).
>
> Style them with `appearance.elements`. See [Elements](/sdks/react/styling#elements).

## Related

> **[CreditHistory](/sdks/react/components/credit-history)**
>
> How credits were used and granted.

> **[Credits](/guides/credits/overview)**
>
> How credit systems work.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.