# Credit Rates

> For the complete machine-readable documentation index, see [llms.txt](https://apidocs.chargebee.com/llms.txt).


The credit rate establishes a connection between a [metered feature](/docs/api/metered_features) and a [credit unit](/docs/api/credit_units). By defining this relationship, it specifies how usage recorded against the metered feature is converted into credits that are drawn down from the subscription's [credit balance](/docs/api/ledger_account_balances).

A metered feature has at most one credit rate, its feature-level credit rate, which applies to every subscription granted its credit unit. To set a different rate for one subscription, use a [credit rate override](/docs/api/credit_rate_overrides). To see the rate in effect for each metered feature on a subscription, use [subscription credit rates](/docs/api/subscription_credit_rates).

## Conversion models[](#conversion-models)

A credit rate converts usage into credits in one of two ways, set by [**conversion\_model**](#conversion_model).

### Per unit (`unit`)[](#per-unit-unit)

Every unit of usage costs [**credit\_cost**](#credit_cost) credits.

**Example:** `opus-usage` costs `1.5` `ai-credits` per token. Using 2,500 tokens draws down 3,750 `ai-credits`.

### Per package (`package`)[](#per-package-package)

Usage is charged in packages of [**package\_size**](#package_size) units, and each package costs [**credit\_cost**](#credit_cost) credits. Packages are counted on the total usage in the subscription's billing term, and a partly used package is charged as a full package. Further usage draws down credits only when it starts a new package in the same term.

**Example:** `opus-usage` costs `10` `ai-credits` per package of `1000` tokens.

Usage sent

Total usage in the term

Packages charged

Credits drawn down

2,500 tokens

2,500 tokens

3

30

300 tokens

2,800 tokens

3

0, because the third package is not used up yet

300 tokens

3,100 tokens

4

10

Package conversion over one billing term.

**How credit rates are versioned**

-   Credit rates are immutable. [Update a credit rate](/docs/api/credit_rates/update-a-credit-rate) creates a new version instead of changing the current one, and never re-prices usage that was already converted.
-   The [**change\_option**](#change_option) of a new version determines which subscriptions move to it and when. Two values are supported: `end_of_term` and `grandfathered`.
-   A version in the history returned by [List credit rate versions](/docs/api/credit_rates/list-credit-rate-versions) is not necessarily the version applied to a given subscription. That depends on the subscription and on each version's `change_option`.

A `credit_cost` of `0` records usage without consuming credits. See [Credit rates and overrides](https://www.chargebee.com/docs/billing/2.0/usage-based-billing/credit-rates-and-overrides).

## How the applicable credit rate is determined[](#how-the-applicable-credit-rate-is-determined)

### With a subscription-level override[](#with-a-subscription-level-override)

When the subscription has a [credit rate override](/docs/api/credit_rate_overrides) for the metered feature, the override applies instead of the feature-level credit rate. The latest version of the override applies from the moment it is created or updated.

When the override is removed, the subscription goes back to the feature-level credit rate that applies to it.

### Without overrides[](#without-overrides)

The first version of a credit rate, created by [Create a credit rate](/docs/api/credit_rates/create-a-credit-rate), applies to all subscriptions. When you update the credit rate, its `change_option` decides which subscriptions get the new version:

-   `grandfathered`: Only subscriptions created after the change get the new version. Existing subscriptions stay on the version they already use.
-   `end_of_term`: Subscriptions created after the change get the new version right away. Existing subscriptions get it when their term renews or resets.

When more than one version applies to a subscription, the latest one is used.

**Subscriptions without the credit unit**

A credit rate applies only to subscriptions that have a credit grant for its [**credit\_unit\_id**](#credit_unit_id). If a subscription has no credit grant for that credit unit, the credit drawdown for usage of the metered feature is rejected.

## Sample Credit-rate

```json
{
  "credit_rate": {
    "id": "fcc_8Jk2LmN4",
    "metered_feature_id": "opus-usage",
    "credit_unit_id": "ai-credits",
    "unit": "tokens",
    "status": "active",
    "conversion_model": "unit",
    "package_size": 1,
    "credit_cost": 1.5,
    "change_option": "immediately",
    "effective_from": 1787088600,
    "version": 0,
    "resource_version": 1787088600000,
    "note": "Initial rate for opus usage",
    "created_by": "admin@acme.com",
    "created_at": 1787088600,
    "updated_by": "admin@acme.com",
    "updated_at": 1787088600,
    "object": "credit_rate"
  }
}
```

## Credit Rates attributes

## Input Parameters

- `id` (required, string, max chars=50)
  Identifier of the credit rate. It stays the same across all versions and is used for logging and correlating versions. Operations identify a credit rate by `metered_feature_id`, not by this value.

- `metered_feature_id` (required, string, max chars=50)
  The identifier of the [metered feature](/docs/api/metered_features) this credit rate belongs to.

- `credit_unit_id` (required, string, max chars=50)
  The identifier of the [credit unit](/docs/api/credit_units) that usage is converted into. It cannot be changed after the credit rate is created. The rate applies only to subscriptions that have a credit grant for this credit unit.

- `unit` (optional, string, max chars=50)
  The unit of measure of the metered feature, such as `tokens`.

- `status` (optional, enumerated string)
  The status of the credit rate. Currently always `active`.
  Possible enum values:
    - `active`
      Usage is converted into credits according to this credit rate.
    - `archived`
      Reserved for future use.

- `conversion_model` (optional, enumerated string)
  Determines how usage is converted into credits. See [Conversion models](#conversion-models).
  Possible enum values:
    - `unit`
      Every unit of usage costs `credit_cost` credits. `package_size` is always `1`.
    - `package`
      Usage is charged in packages of `package_size` units, and each package costs `credit_cost` credits. Packages are counted on the total usage in the billing term, and a partly used package is charged as a full package.

- `package_size` (optional, bigdecimal, min=1E-9, max=999999999.999999999)
  The number of usage units in one package. Applies only when `conversion_model` is `package`; for `unit` it is always `1`.
  
  **Constraints**
  
  -   Must be greater than `0`.
  -   Supports up to 9 decimal places.

- `credit_cost` (optional, bigdecimal, min=0, max=999999999.999999999)
  The credits charged for each unit of usage when `conversion_model` is `unit`, or for each package of `package_size` units when `conversion_model` is `package`.
  
  **Constraints**
  
  -   Supports up to 9 decimal places.

- `change_option` (optional, enumerated string)
  Determines which subscriptions get this version and when. Updates accept `end_of_term` or `grandfathered`. See [How the applicable credit rate is determined](#how-the-applicable-credit-rate-is-determined).
  Possible enum values:
    - `grandfathered`
      Only subscriptions created after this version get it. Existing subscriptions stay on the version they already use.
    - `end_of_term`
      Subscriptions created after this version get it right away. Existing subscriptions get it when their term renews or resets.
    - `immediately`
      Set automatically on the first version of a credit rate. Not accepted by [Update a credit rate](/docs/api/credit_rates/update-a-credit-rate).

- `effective_from` (optional, long)
  The time this version takes effect, in UTC seconds. For `end_of_term` and `grandfathered` versions, this is the time of the update; existing subscriptions pick up the version later, or not at all, according to `change_option`.

- `effective_to` (optional, long)
  The time this version stopped applying, in UTC seconds. Not returned for the version in effect.

- `version` (optional, long)
  The version number, starting at `0` for the first version and increasing by one with each update. Use it to display version history; use `resource_version` to detect changes.

- `resource_version` (optional, long)
  A timestamp in milliseconds identifying this version of the credit rate. Versions are immutable, so the value never changes for a version; each update creates a new version with a new `resource_version`. Use it to detect changes when syncing. It is not a version number; see `version` for that.

- `updated_at` (optional, timestamp(UTC) in seconds)
  The time at which the credit rate was last modified, in UTC seconds.

- `note` (optional, string, max chars=500)
  The reason given for this change, shown in the version history.

- `created_by` (optional, string, max chars=100)
  The email of the user who created the credit rate.

- `created_at` (optional, long)
  The time at which the credit rate was created, in UTC seconds.

- `updated_by` (optional, string, max chars=100)
  The email of the user who last modified the credit rate.

