In this quick tutorial, we’ll set up pricing and billing for an AI chatbot product. This product has a Pro tier, which comes with 50 chat messages and access to Pro Analytics.

Step 1: Define product features

We can define the chatbot’s features in the Autumn dashboard. We’ll create two features:

  1. “Chat messages”: a metered feature, as access is dependent on its usage

  2. “Pro Analytics”: a boolean feature, as it’s a simple on-off toggle depending on the tier

Creating a boolean feature just needs a name and ID. Metered features rely on reporting usage events (see Step 5) so we can keep track of how much allowance each customer has left. We need to define the name of the event we’ll be sending from our application.

Step 2: Create a product

Next, let’s create a product. We’ll call it “Pro Tier”, and under Entitlements, we’ll add our 50 chat messages per month and Pro Analytics. We’ll then add a pricing of $99 per month.

Step 3: Create a customer

Now we need to create our first customer. You can do this either via the API or dashboard. The best part… you can use your own, internal customer IDs!

const response = await fetch('https://api.useautumn.com/v1/customers', {
  method: "POST",
  headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
  body: JSON.stringify({
    "id": "my_personal_id",
    "name": "John Doe",
    "email": "john.doe@gmail.com"
  })
})

Step 4: Attach a product on purchase

When this customer purchases Pro Tier, we’ll attach our Pro product to the customer. Once again, you can do this via Dashboard or API. This step will involve billing the customer, so if you haven’t set up your Stripe credentials yet, you will be prompted to do so.

If a customer needs to make a card payment, this will return a Stripe checkout URL. If we have the card already on file, we’ll automatically handle billing.

Our design philosophy is that you shouldn’t have to handle upgrades, downgrades, or 258 webhook statuses. So whenever you want to assign a product to a customer, all you need to do is call this endpoint—Autumn will handle all this for you!

const response = await fetch('https://api.useautumn.com/v1/attach', {
  method: "POST",
  headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
  body: JSON.stringify({
    "customer_id": "my_personal_id",
    "product_id": "prod_2rwydCAcuUp913PqoZwOjpy4aDM"
  })
})

const data = await response.json()

if (data.checkout_url) {
  // Redirect user to checkout_url
}

Step 5: Check access and send usage events

Finally from your application, whenever a customer tries to use one of your features, first check if they’re entitled by calling the endpoint below. If it’s a usage-based feature, make sure to send us the events.

// 1. Check if customer is entitled to feature
const response = await fetch('https://api.useautumn.com/v1/entitled', {
  method: "POST",
  headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
  body: JSON.stringify({
    "customer_id": "my_personal_id",
    "feature_id": "premium_msg"
  })
})

// 2. Check if user is allowed
let data = await response.json()
if (!data.allowed) {
  throw new Error(`feature not allowed`)
}

// 3. Send event if user accesses feature
await fetch('https://api.useautumn.com/v1/events', {
  method: "POST",
  headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
  body: JSON.stringify({
    "customer_id": "my_personal_id",
    "event_name": "premium_msg"
  })
})