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.
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.jsonPrefer 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
| Prop | Type | Default | Description |
|---|---|---|---|
| title | string | "API credits" | Card header text. |
| description | string | none | Optional line under the header. |
| balance | number | none | Credits currently remaining. |
| typicalMonthlyUsage | number | none | Credits the account typically uses in a month. The balance bar is drawn as balance divided by this number. |
| lowBalanceThreshold | number | 20 | Percent of typicalMonthlyUsage, at or below which the low-balance warning shows and the bar turns amber. |
| topUpOptions | TopUpOption[] | none | Fixed top-up amounts rendered as three link buttons. |
| className | string | none | Extra 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
More Billing Blocks
View all →Billing Invoice List
Invoice history table with status badges, formatted amounts, and a per-row download link, built with shadcn/ui and Tailwind CSS.
Billing Failed Payment Alert
High-contrast failed-payment alert with a message, a retry button, and an optional update-payment-method button, built with shadcn/ui and Tailwind CSS.
Billing Credit Balance
Compact credit balance card with a large total, an optional purchased-versus-promotional breakdown, a low-balance notice, and a top-up button.
Billing Payment Methods
A saved payment method list for React and Next.js with brand icons, a default badge, near-expiry warnings, and remove/set-default actions per row.
Billing Add Card
A card entry form for React and Next.js with auto-formatted fields, internal brand detection, and per-field validation feedback built with shadcn/ui and Tailwind CSS.
Billing Coupon Code
An inline promo code input for React and Next.js with a simulated loading state, an applied summary showing the discount amount, and an invalid-code message.