Credit systems allow you to track and limit the usage of multiple different features from a shared balance. This can simplift billing when you have many different usage-based features, and they all cost different amounts.

Creating a credit system

Make sure you have some metered features created before creating a credit system.

  1. Navigate to the products page
  2. Click the “Features” tab
  3. Click ”+ Credit System”
  4. Add each metered feature you want to affect the credit system.
  5. For each feature, define how many credits each unit of usage (ie, the value field in the events route) should be worth.
  6. Click “Create”

Example

If each audio-transcription-minute is worth 3 credits, then using 6 minutes of audio transcription will cost 18 credits.

Now you can add these credits as a product item within a product. Such as 50 credits per month or $1 per credit.

Using credits via the API

When implementing a credit system into your application, you should interact with the underlying features (not the credit system itself).

curl -X POST "https://api.useautumn.com/v1/entitled" \
  -H "Authorization: Bearer am_sk_1234567890" \
  -H "Content-Type: application/json" \
  -d '{
    "customer_id": "user-123",
    "feature_id": "audio-transcription-minutes",
  }'

The response will contain the ID of the credit system you defined.

{
  "customer_id": "john-mcyeo",
  "feature_id": "small-model-tokens",
  "code": "feature_found",
  "allowed": true,
  "balances": [
    {
      "feature_id": "transcription-credits",
      "unlimited": false,
      "balance": 10000
    }
  ]
}

In this case, we have a balance of 10,000 credits remaining, so we’re allowed to use our audio-transcription-minutes feature.

When checking for feature access, if a feature is not defined in the credit system (and not in any other product items separately), it will return allowed: false

Now we can send a usage event:

curl -X POST "https://api.useautumn.com/v1/event" \
-H "Authorization: Bearer am_sk_1234567890" \
-H "Content-Type: application/json" \
-d '{
"customer_id": "user-123",
"feature_id": "audio-transcription-minutes",
"value": 10
}'
{
    "message": "Event recorded successfully",
    "event_id": "event_123",
    "customer_id": "user-123",
    "feature_id": "audio-transcription-minutes"
}

In this case, if each audio-transcription-minute costs 3 credits, since we sent a usage event for 10 minutes (value: 10), it will cost us 30 credits. We started with 10000 credits and our remaining balance will be 9970 credits.

Monetary credits

You may want your credit system to represent a monetary value: eg, $10 of credits. To implement this, you typically want to treat each credit as 1 cent.

  1. When creating your credit system, make sure that you define credit amounts in the per-cent cost
    Eg: if each audio-transcription-minute costs 7 cents, our credit amount will be 7.
  2. Set any included usage of credits in cents
    Eg, if customers get 5 USD credits for free, they should have an included usage of 500.
  3. Set the cost of each credit to 1 cent (0.01) when handling prices

See the credits pricing guide for a more detailed example of setting up a monetary credits system

Credits Example