Skip to main content
Custom credit consumption formulas allow you to define how usage events convert into credit deductions for metered features. This provides fine-grained control over consumption logic and supports advanced pricing models where usage is not uniform.

Overview

Custom formulas enable you to specify how event dimensions (e.g., token count, file count, duration) influence credit burn. Each metered feature can define its own formula. Stigg then applies the formula in real time when usage events are reported. This feature works with all existing credit-based pricing models and integrates automatically with credit enforcement, metering, and the credit ledger. Use this feature if:
  • Your usage events contain multiple metadata fields that affect cost.
  • Different workloads or models should consume credits at different rates.
  • You need more accuracy than fixed per-unit pricing provides.
  • Your product uses AI, media processing, data transformations, or variable-intensity workloads.

Key capabilities

  • Custom event-based formulas: Define mathematical expressions that map event dimensions to credit consumption.
  • Per-feature calculation: Each metered feature can apply a different formula.
  • Use event dimensions as parameters: Reference dimensions such as tokens, files_processed, or any event metadata field.
  • Real-time deduction: Credits are deducted immediately upon event ingestion.
  • Full audit trail: All calculations are visible in the credit ledger, including parameter values and resulting credit burn.

Requirements

  • Advanced formulas are available only for meters that use Sum or Count aggregation.
  • The formula field accepts up to 255 characters.

Formula syntax

The formula is evaluated once per usage event. Its result is the number of credits that event consumes.
  • Dimensions: reference a dimension with the dimensions. prefix, followed by the dimension name exactly as it’s reported on the event, for example dimensions.units. A bare name like units fails validation.
  • Numbers: integers and decimals, for example 2 or 1.5.
  • Strings: quoted text, for comparing against string dimensions, for example 'standard'.
  • Arithmetic: +, -, *, /, ^.
  • Comparisons: ==, !=, <, <=, >, >=.
  • Conditions: if(condition, valueIfTrue, valueIfFalse).
  • Functions: min, max, abs, round, ceil, floor.
Enter the expression only. Don’t prefix it with an assignment such as credits_used =.

Missing dimensions and invalid results

Every dimension the formula references must be present on the event. If one is missing, the event consumes 0 credits and no error is raised. To make a dimension optional, guard it with if so the formula only uses its value when it’s present. An event also consumes 0 credits when the formula evaluates to a negative number or to infinity, for example after a division by zero.
Test new formulas in a non-production environment before publishing them to live customers.

Examples

Weighted inputs

Charge each workload type at its own rate:

Input and output tokens

Charge output tokens at twice the input rate:

Rate by tier

Charge double for anything other than the standard tier:

Round up to the minute

Charge per started minute of processing time:

Minimum charge per event

Charge at least 1 credit, even for small events:

Configuration guide

  1. Go to Product catalog.
  2. Select Plans.
  3. Select a plan.
  4. Select Edit.
  5. Scroll down to the Price section.
  6. Click Edit.
  7. In the Set price section, scroll down to Credit consumption.
  8. Select the configuration, for example, Prototype generations.
  9. Set the Calculation mode to Advanced formula.
  10. Enter the formula into the Formula field.
  11. Use Preview to check the result. Select Load from source to evaluate the formula against a real event.
  12. Click Save changes.
  13. Click Review and publish.
  14. Set what the changes will affect.
  15. Click Publish changes.