Meterline: usage billing and prepaid credits
Lumen AI, an inference API company, bills tokens in price tiers, GPU-seconds through event-based billing, and prepaid credit packs on Maxio Advanced Billing.
The story
Lumen AI is a fictional company selling an inference API. It bills its own customers on Maxio Advanced Billing with a monthly platform fee, input and output tokens metered in price tiers (in millions of tokens, MTok), GPU-seconds through event-based billing, and prepaid "inference credit" packs that are drawn down. Meterline is the console Lumen's billing engineer uses to send usage, watch each customer's tier and credit balance, and preview the next invoice.
| At a glance | |
|---|---|
| Use case | Usage-based billing, tiered pricing, event-based billing, prepaid credits |
| SDK operations | 14 |
| Live app | mxo-meterline.pages.dev |
Screens
| Screen | What you see and do | SDK calls |
|---|---|---|
| Usage Pulse | A live token counter over the price-tier bands, with a run-rate projection and the date each customer crosses into the next tier. Beside it, a tier ladder places all 12 customers on their tier | subscriptions.listSubscriptions, components.listComponents, subscriptionComponents.listSubscriptionComponentsForSite, subscriptionComponents.listUsages |
| Ingest | Send metered usage, or GPU-second events one at a time or as a batch of 25, and watch the meter move across tier breaks | subscriptionComponents.createUsage, subscriptionComponents.recordEvent, subscriptionComponents.bulkRecordEvents |
| Credits | A burn-down of each prepaid credit balance with a forecast of the run-out date. Preview and then add a top-up, or extend an expiry date | subscriptionComponents.listAllocations, subscriptionComponents.previewAllocations, subscriptionComponents.allocateComponent, subscriptionComponents.updatePrepaidUsageAllocationExpirationDate |
| Projected invoice | The next renewal as a waterfall: platform fee, tokens split by tier, GPU-seconds, credits applied, tax and total | subscriptionStatus.previewRenewal, subscriptionComponents.listSubscriptionComponents, entitlements.readSubscriptionEntitlements |
SDK operations
| Operation | SDK method | Used for |
|---|---|---|
| List subscriptions | subscriptions.listSubscriptions | The customer roster |
| List components | components.listComponents | Token, GPU and credit components with their price tiers |
| List subscription components for a site | subscriptionComponents.listSubscriptionComponentsForSite | Every customer's usage this period in one call |
| List usages | subscriptionComponents.listUsages | The usage history behind the meter |
| Create usage | subscriptionComponents.createUsage | Record metered tokens |
| Record event | subscriptionComponents.recordEvent | One GPU-seconds event |
| Bulk record events | subscriptionComponents.bulkRecordEvents | A batch of GPU-seconds events |
| List allocations | subscriptionComponents.listAllocations | Credit top-ups and their expiries |
| Preview allocations | subscriptionComponents.previewAllocations | Price a top-up before it is made |
| Allocate component | subscriptionComponents.allocateComponent | Add prepaid credits |
| Update prepaid allocation expiration | subscriptionComponents.updatePrepaidUsageAllocationExpirationDate | Extend a credit pack |
| Preview renewal | subscriptionStatus.previewRenewal | The projected invoice |
| List subscription components | subscriptionComponents.listSubscriptionComponents | One customer's components with historic usage |
| Read subscription entitlements | entitlements.readSubscriptionEntitlements | The plan's entitlements |
Code: record usage and preview the invoice
// Metered tokens, addressed by the subscription's reference
const { usage } = await client.subscriptionComponents.createUsage({
subscriptionIdOrReference: "lumen-orbital-health",
componentId: inputTokensId,
body: { usage: { quantity: 120, memo: "Hourly sync 14:00" } },
});
// The next invoice, line by line
const { renewalPreview } = await client.subscriptionStatus.previewRenewal({ subscriptionId });Errors shown on purpose
- Maxio 422s: usage on a canceled customer, drawing more credits than remain, a zero-credit top-up preview, moving an expiry date earlier, and previewing the renewal of a canceled subscription.
- App rules: negative usage, an unknown subscription reference, a GPU event over 24 hours and a top-up over 50,000 credits are blocked before Maxio sees them.
Use cases: sample apps built with the Context Plugin
Four working Maxio Advanced Billing apps, each built by a coding agent with the Maxio Context Plugin installed and calling Maxio only through the typed TypeScript SDK.
Shift: plan changes with proration
Northwind Analytics changes plans, seats and add-ons, previewing every proration first, and keeps customers with coupons and scheduled cancellations.
