Introducing the Chargebee CLI

Credit Rates

The credit rate establishes a connection between a metered feature and a credit unit. 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.

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. To see the rate in effect for each metered feature on a subscription, use subscription credit rates.

Conversion models

A credit rate converts usage into credits in one of two ways, set by conversion_model.

How credit rates are versioned

  • Credit rates are immutable. 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 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 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.

How the applicable credit rate is determined

Subscriptions without the credit unit

A credit rate applies only to subscriptions that have a credit grant for its 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 rateJSON

Credit Rates attributes

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 this credit rate belongs to.

credit_unit_id
required, string, max chars=50

The identifier of the credit unit 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.

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.

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.

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.

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.