Skip to navigation

Chat subscription with credit buckets

Wingtip is a multi-model chat app sold as a self-serve subscription: Base at $20 a month and Premier at $200 with 10 times the usage. Every message costs credits that follow Wingtip’s inference cost, 1 credit to $0.001. Credits come from two buckets, spent in order: one that refills every 4 hours, and a monthly one.

This example uses:

The calls omit the headers every request sends: Authorization, Paid-Version, the Paid-Beta opt-in each endpoint requires (such as credits=v1 for credit endpoints, or events=v1,event_costs=v1,credits=v1 for an event with costs and a hold), and an Idempotency-Key on writes. See request headers and idempotency.

The pricing

BucketBasePremierRefillsUnused credits
4-hour50500Every 4 hours from the start of the month’s grantLost at the next refill
Monthly2,00020,000Each month, with the subscriptionLost at renewal

Credit rates follow inference costs one to one:

UsageSmall models (model-small-*)Large models (model-large-*, and any other model)
Input, per 1M tokens800 credits5,000
Cached input, per 1M tokens300300
Output, per 1M tokens4,00025,000
Prompt over 200,000 input tokensInput and cached input × 2Input and cached input × 2
Web search; attached file10 each; 5 each10 each; 5 each

Setup

Create a credit currency for the credits. With no conversion, usage past the balance is recorded as overage but never billed:

POST /v1/credit-currencies
{
"key": "wingtip_credits",
"name": "Wingtip credits",
"conversion": null
}

Create the product:

POST /v1/products
{
"externalId": "wingtip_chat",
"name": "Wingtip",
"displayName": "Wingtip"
}

Wingtip sends one message.completed event per message, with the model call as an inference cost line. Create a meter per token type that reads that line, grouped by model:

POST /v1/meters
{
"key": "input_tokens",
"name": "Input tokens",
"eventNames": ["message.completed"],
"measure": {
"type": "events",
"events": {
"aggregation": { "type": "sum", "sum": { "path": "cost.inference.uncachedInputTokens" } },
"unit": "token",
"groupBy": ["cost.inference.model"]
}
}
}

Do the same for cache_read_tokens (path cost.inference.cacheReadInputTokens) and output_tokens (path cost.inference.outputTokens); Paid derives uncachedInputTokens, so cached input is counted once. Two more meters, web_searches (unit search) and attachments (unit file), sum payload.webSearches and payload.attachments the same way.

Set up a rate card, wingtip_credit_rates, in the wingtip_credits credit currency. The rate card API is in preview; Introduction to pricing explains how a rate card prices meters. Small models match by prefix. Rates with no match are the fallback, so large models, and any model added later, get large-model rates. A long-context modifier doubles input and cached input on any message over 200,000 input tokens.

MeterModelCredits
input_tokensmodel-small*800 per million
output_tokensmodel-small*4,000 per million
input_tokensany other5,000 per million
output_tokensany other25,000 per million
cache_read_tokensany300 per million
web_searchesany10 per search
attachmentsany5 per file

Each plan is one flat monthly price whose grants list fills two buckets. Create the Base price. Price amounts are in cents, as decimal strings; credit amounts are in credits. The price has no unit, so the line’s quantity is 1 and each amountPerUnit is a bucket size:

POST /v1/prices
{
"product": "wingtip_chat",
"name": "Base monthly",
"displayName": "Wingtip Base",
"currency": "usd",
"type": "recurring",
"recurring": {
"interval": "month",
"pricing": { "type": "perUnit", "perUnit": { "unitAmount": "2000" } },
"grants": [
{
"creditCurrency": "wingtip_credits",
"amountPerUnit": "2000",
"grantedOn": "invoicePaid",
"expiresAfter": { "value": "1", "unit": "month" }
},
{
"creditCurrency": "wingtip_credits",
"amountPerUnit": "50",
"grantedOn": "invoicePaid",
"expiresAfter": { "value": "1", "unit": "month" },
"refill": { "every": { "value": "4", "unit": "hour" } }
}
]
}
}

The Premier price is the same with "unitAmount": "20000" and grants of "20000" and "500". Both grants arrive when the invoice is paid, so a failed renewal refills neither.

Create the plans, each with its price and the shared rate card:

POST /v1/plans
{
"externalId": "base_monthly",
"name": "Base",
"displayName": "Wingtip Base",
"lines": [
{ "type": "price", "price": { "price": "prc_base20Mo" } },
{ "type": "rateCard", "rateCard": { "rateCard": "wingtip_credit_rates" } }
],
"upgradePath": { "group": "wingtip_monthly", "position": 1 },
"default": true
}

premier_monthly uses the Premier price and "position": 2.

Signing up a subscriber

Create the customer at sign-up, store its cus_ ID on the user, and send it on every event:

POST /v1/customers
{
"externalId": "user_51c9",
"name": "Mara Ellison",
"email": "mara@example.com",
"currency": "usd"
}

Create an order from the plan, starting at checkout:

POST /v1/orders
{
"customer": "cus_8HqL2xT",
"plan": { "plan": "base_monthly" },
"startsAt": "2026-11-03T14:20:00Z",
"billingCycle": { "interval": "month" },
"paymentTerms": "dueOnReceipt"
}

Then activate it with POST /v1/orders/ord_4Rt8Zp/activate, which takes no body. Each invoice has one line, Wingtip Base at $20.00: messages are paid in credits, and overage is never billed.

The 4-hour grant’s windows start when the month’s invoice is paid: a subscriber who paid at 14:20 refills at 14:20, 18:20, 22:20 and so on, back to 50 each time. Wingtip has nothing to schedule.

Sending usage

Before calling the model, Wingtip holds its estimate, assuming 2,000 output tokens; the check is atomic, so two messages at once can’t both spend the last credits. For a small-model question with a web search, the estimate is 3.2 input + 8 output + 10 search = 21.2:

POST /v1/credit-holds
{
"customer": "cus_8HqL2xT",
"creditCurrency": "wingtip_credits",
"amount": "21.2",
"correlationId": "msg_7f3a"
}

When the message finishes, Wingtip sends one event that names the hold. Paid prices the inference line from its catalog, so the event also records Wingtip’s real cost:

POST /v1/events
{
"eventName": "message.completed",
"customer": "cus_8HqL2xT",
"product": "wingtip_chat",
"dedupeKey": "msg_7f3a",
"correlationId": "thread_2b91",
"creditHold": "hold_Qm3v9",
"timestamp": "2026-11-10T18:36:12Z",
"payload": { "webSearches": 1, "attachments": 0 },
"cost": [
{
"type": "inference",
"inference": {
"operation": "chat",
"provider": "model-provider",
"model": "model-small-2026-09",
"inputTokens": 4000,
"cacheReadInputTokens": 0,
"outputTokens": 600
}
}
]
}

The event spends the actual 15.6 credits and settles the hold; the other 5.6 are free again. An actual above the hold is spent too, as unbilled overage if the balance runs out. If the provider errors before any output, Wingtip releases the hold with POST /v1/credit-holds/hold_Qm3v9/release. An unsettled hold lapses after 15 minutes. A hold the balance can’t cover fails with 409, so Wingtip shows the time to the next refill or offers a small model.

What typical messages cost:

MessageTokensCredits
Small-model question4,000 in, 600 out4,000 × 800 ÷ 1M + 600 × 4,000 ÷ 1M = 3.2 + 2.4 = 5.6
… with a web searchThe same, plus 1 search5.6 + 10 = 15.6
Large-model question6,000 in, 800 out30 + 20 = 50
PDF analysis (large model)62,000 in, 2,000 out, 1 file310 + 50 + 5 = 365
Codebase dump (large model)250,000 in, 4,000 out1,250 × 2 (long context) + 100 = 2,600
Follow-up in that thread256,000 in (250,000 cached), 3,000 out30 × 2 + 75 × 2 + 75 = 285

How a session spends the buckets

Grants are spent soonest-forfeited first, counting a refilling grant’s nextRefillAt. The 4-hour grant’s credits are forfeited at its next refill and the monthly grant’s at renewal, so the waterfall needs no configuration.

On 10 November at 18:35, in the 18:20 to 22:20 window, the subscriber has 50 in the 4-hour bucket and 1,700 left in the monthly bucket:

MessageCredits4-hourMonthly
Start501,700
Small-model question5.644.41,700
… with a web search15.628.81,700
Large-model question500 (28.8 spent)1,678.8 (21.2 spent)
PDF analysis36501,313.8

At 22:20 the 4-hour grant refills to 50, so 1,363.8 credits are spendable. A codebase dump at 22:50 needs about 2,600, so its hold fails with 409, and Wingtip offers a small model or shows the time to the next refill.

An illustrative month

Each 30-day month has 180 4-hour windows, and each invoice is the flat plan price.

A typical Base subscriber ($20.00 invoice), active in about 90 windows:

UsageMessagesCredits eachCredits
Small-model questions4505.62,520
Small-model questions with a web search4015.6624
Large-model questions20501,000
PDF analyses43651,460
Total5145,604

3,800 credits come from the 4-hour bucket (of 9,000 offered; 5,200 lapse) and 1,804 from the monthly bucket (196 expire at renewal). 5,604 credits is $5.60 of inference against $20.00, a $14.40 margin.

A Premier subscriber ($200.00 invoice) who pastes codebases into a large model:

UsageMessagesCredits eachCredits
Small-model questions1,0005.65,600
Large-model questions3005015,000
Codebase dumps82,60020,800
Follow-ups in those threads8028522,800
PDF analyses163655,840
Total1,40470,040

The credits come from the 4-hour bucket (50,040 of 90,000 offered) and the whole monthly bucket (20,000): 70,040 in all, or $70.04 of inference against $200.00, a $129.96 margin. The codebase threads alone cost 20,800 + 22,800 = 43,600 credits, 62% of the month.

What subscribers see

The app shows each bucket and its countdown from the subscriber’s grants, GET /v1/credit-grants?customer=cus_8HqL2xT&creditCurrency=wingtip_credits. Each grant carries its own available, and nextRefillAt or expiresAt. At 18:40 in the session above, the 4-hour grant shows 28.8 with nextRefillAt 22:20 (“refills in 3h 40m”), and the monthly grant 1,700. The total spendable now, net of held credits, is on the credit balance. Because a credit is pinned to $0.001 of cost, usage summaries grouped by customer show how close each subscriber comes to their price. The buckets cap it: a Base subscriber can spend at most 11,000 credits a month ($11.00 against $20.00), and a Premier one 110,000 ($110.00 against $200.00).

Upgrading to Premier

A subscriber upgrades on 18 November, in the 3 November to 3 December period. Preview the amendment:

POST /v1/orders/ord_4Rt8Zp/amendments/preview
{
"changes": [{ "type": "changePlan", "changePlan": { "plan": "premier_monthly" } }],
"expectedVersion": 1,
"proration": "prorate"
}

The preview returns direction: "upgrade". 18 November to 2 December is 15 of the period’s 30 days, so Base is credited $20.00 × 15 ÷ 30 = −$10.00 and Premier charged $200.00 × 15 ÷ 30 = $100.00: +$90.00. Apply it with POST /v1/orders/ord_4Rt8Zp/amendments, sending the same changes and proration plus the previewToken.

changePlan takes effect immediately, so Wingtip applies downgrades itself when the period ends.