> ## Documentation Index
> Fetch the complete documentation index at: https://docs.stigg.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Example - OpenAI pricing

## 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 → Credits → Add credit type**.
   * Set the **Name** (e.g., `USD Credits`) and unit labels (e.g., singular: *credit*, plural: *credits*).
   * Fractional conversion rates (e.g., `0.002` credits per token) are supported when you configure credit consumption in the plan.

2. Create metered features using Raw events:
   * Create features for:
     * `gpt-X.input_tokens`
     * `gpt-X.output_tokens`
     * *(Optional)* `cached_input_tokens` (if you discount cached prompts)
   * Set **Feature type** to **Meter** and **Meter type** to **Raw events**.

<Note>
  Only **Raw events** (event-based) meter type is supported for credit consumption mapping. **Calculated usage** features will not appear in the credit consumption configuration.
</Note>

* After configuring the event filters and aggregation method, you will reach the unit name step. Set the singular unit to *token* - the plural (*tokens*) will be populated automatically.

3. 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](./prepaid-credits)**.

4. Add the metered features to the plan's entitlements:
   * In the plan, scroll to the **Entitlements** section and click **+ Add**.
   * Search for and select each feature you created (`gpt-X.input_tokens`, `gpt-X.output_tokens`, etc.).
   * Click **Add** to confirm.

<Note>
  This step is required before mapping features to credit costs. If you skip it, the **Credit consumption** section will show **No matching metered features**.
</Note>

5. Map each metered feature to a credit cost:
   * In the plan's **Price** section, under **Credit consumption**, click **+ Add**.
   * Select the metered feature and define the conversion rate, for example:
     * `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 generic `input_tokens` feature with a `model` dimension in metadata.

6. Publish the plan by clicking **Publish** so it’s selectable for subscriptions.

7. Create a customer:
   * Go to **Customers → +New customer** and set identifiers you’ll use when reporting events (e.g., `customerId`, optional `resourceId`).

8. 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**.

9. 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.

10. 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.
