Staaarter

Billing API Credits

A credit balance card for pay-as-you-go and API-metered products. It shows the current credit balance as a large number, a bar comparing that balance to the account's typical monthly usage, and a low-balance warning once the balance drops under a configurable threshold. A row of top-up buttons below links out to fixed-amount purchase flows. Built for developer platforms and AI products billed by consumption instead of a flat subscription.

By Staaarter Team
Billing
Updated March 27, 2026
Docs
Live preview

Docs

Installation

A real shadcn registry command, not a copy-paste stand-in: it fetches this block plus its card, button dependencies and any missing npm packages, and installs them straight into your project.

npx shadcn add https://staaarter.com/r/billing-api-credits.json

Prefer not to use the CLI? Copy the source from the Code toggle above into src/components/blocks/billing/billing20.tsx instead.

Usage

The file also exports billing20Demo, the exact props behind the preview above. Spread it to get a working section in one line, then replace it with your own data.

import { Billing20, billing20Demo } from "@/components/blocks/billing/billing20";

export default function Page() {
  return <Billing20 {...billing20Demo} />;
}

Props

PropTypeDefaultDescription
titlestring"API credits"Card header text.
descriptionstringnoneOptional line under the header.
balancenumbernoneCredits currently remaining.
typicalMonthlyUsagenumbernoneCredits the account typically uses in a month. The balance bar is drawn as balance divided by this number.
lowBalanceThresholdnumber20Percent of typicalMonthlyUsage, at or below which the low-balance warning shows and the bar turns amber.
topUpOptionsTopUpOption[]noneFixed top-up amounts rendered as three link buttons.
classNamestringnoneExtra classes for the outer card.

Types

interface TopUpOption {
  amount: string;
  credits: string;
  href: string;
}

Behavior notes

  • The balance bar's fill percent is balance divided by typicalMonthlyUsage, clamped to 100, so it reads as 'how much of a normal month is left' rather than a fraction of some fixed cap.
  • The bar and the low-balance warning both switch on when that percent falls at or below lowBalanceThreshold, computed on every render, there's no separate flag to set by hand.
  • Top-up buttons are plain links (topUpOptions[].href), not buttons with onClick handlers, so wiring a real purchase means pointing each href at your checkout route.
  • The credits grid is fixed at three columns regardless of how many topUpOptions are passed; four or more items will wrap onto a second row.

Frequently asked questions