Modeling OpenAI-style token pricing in Stigg
Bill for model usage by input and output tokens, with different rates per model if needed, and expose a single AI tokens currency to customers.-
Create a credit currency (USD):
- Go to Product Catalog → Credit currencies → +New.
- Set Display name:
USD Credits
, Symbol:USD
, and unit labels (e.g., credit / credits). - Use decimal precision so fractional rates (e.g.,
0.002
credits per token) are supported.
-
Create event-based metered features:
- Create features for:
gpt-X.input_tokens
gpt-X.output_tokens
- (Optional)
cached_input_tokens
(if you discount cached prompts)
- Use event-based metering and set the unit to tokens.
- Create features for:
-
Create a prepaid, paid plan:
- Go to Product Catalog → Plans → +New plan.
- Plan type: Paid → Billing model: Prepaid.
- See the full plan setup in Prepaid credits.
-
Map each metered feature to a credit cost:
- In Credit consumption, define conversions such as:
gpt-X.input_tokens
→A credits / 1,000,000 tokens
gpt-X.output_tokens
→B credits / 1,000,000 tokens
- (Optional)
cached_input_tokens
→ discounted rate
- Tip: You can keep the model in the feature name (
gpt-4o.input_tokens
) or use a genericinput_tokens
feature with amodel
dimension in metadata.
- In Credit consumption, define conversions such as:
- Publish the plan by clicking Publish so it’s selectable for subscriptions.
-
Create a customer:
- Go to Customers → +New customer and set identifiers you’ll use when reporting events (e.g.,
customerId
, optionalresourceId
).
- Go to Customers → +New customer and set identifiers you’ll use when reporting events (e.g.,
-
Create a subscription to the prepaid plan:
- On the customer, click Create subscription.
- Choose the product, the new prepaid plan, and (if applicable) price localization.
- (Optional) Add Included credits (purchase or promo), set expiration.
- (Optional) Configure Auto top-up thresholds and caps.
- Click Create Subscription.
-
Top up the customer balance:
- From the customer/subscription view, use Add to credit balance to purchase credits (admin), or let customers self-serve via your checkout flow.
- Confirm the new Credits balance.
-
Report events to Stigg (watch the balance draw down):
- For every request, report usage events for the relevant features:
featureId
:gpt-X.input_tokens
orgpt-X.output_tokens
customerId
(and optionalresourceId
)event_id
(unique),event_timestamp
value
(token count for that event)
- Stigg converts tokens → credits using the configured rate at the time of the event, decrementing the prepaid balance in real time.
- For every request, report usage events for the relevant features: