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.
  1. 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.
  2. 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.
  3. Create a prepaid, paid plan:
    • Go to Product Catalog → Plans → +New plan.
    • Plan type: PaidBilling model: Prepaid.
    • See the full plan setup in Prepaid credits.
  4. Map each metered feature to a credit cost:
    • In Credit consumption, define conversions such as:
      • gpt-X.input_tokensA credits / 1,000,000 tokens
      • gpt-X.output_tokensB 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 generic input_tokens feature with a model dimension in metadata.
  5. Publish the plan by clicking Publish so it’s selectable for subscriptions.
  6. Create a customer:
    • Go to Customers → +New customer and set identifiers you’ll use when reporting events (e.g., customerId, optional resourceId).
  7. 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.
  8. 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.
  9. Report events to Stigg (watch the balance draw down):
    • For every request, report usage events for the relevant features:
      • featureId: gpt-X.input_tokens or gpt-X.output_tokens
      • customerId (and optional resourceId)
      • 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.