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:
- Credit currencies for the credits
- Products, meters and a rate card, in preview, that prices messages in credits
- Prices whose grants fill the buckets, and plans
- Customers and orders
- Credit holds, events and credit grants
- Amendments for an upgrade
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
Credit rates follow inference costs one to one:
Setup
Create a credit currency for the credits. With no conversion, usage past the balance is recorded as overage but never billed:
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:
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.
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:
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:
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:
Create an order from the plan, starting at checkout:
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:
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:
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:
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:
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:
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:
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:
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.