Skip to main content
Typically, your users should get access to different features and usage limits, depending on their plan. Autumn handles your customer’s payments and grants them the features defined in your plan configuration. There are 2 functions you need to enforce limits and gating:
  • check for feature access, before allowing a user to do something
  • track the usage in Autumn afterwards (if needed)
This example will continue from before: a 2-tier pricing model for a chatbot.
This guide shows an asynchronous approach to checking and tracking. You can also check and reserve balance in a single, atomic API call for concurrent events.

Checking feature access

Check if a user has enough remaining balance of messages, before executing the action. The feature_id used here is defined by you when you create the feature in Autumn.
import { useCustomer } from "autumn-js/react";

export function SendChatMessage() {
	const { check, refetch } = useCustomer();

	const handleSendMessage = async () => {
		const { data } = check({ featureId: "messages" });

		if (!data?.allowed) {
			alert("You're out of messages");
		} else {
			//send chatbot message
			//then, refresh customer usage data
			await refetch();
		}
	};
}
When using React hooks, you have access to the customer state object, which you can use to display billing data to your users (subscription status, feature permissions, usage balances, etc).You can use the client-side check function to gate features and show paywalls. Permissions are determined by reading the local customer state, so no call to Autumn’s API is made. The “true” state should always be fetched server-side.
You can also use check to gate boolean features (non-metered features), such as access to “premium AI models”.

Tracking usage

After the user has successfully used a chatbot message, you can record the usage in Autumn. This will decrement the user’s message balance.
//Your own function to send the chat message

//then record 1 message used
await autumn.track({
  customer_id: "user_or_org_id_from_auth",
  feature_id: "messages",
  value: 1
});
Once you send usage events, you can verify their receipt in the Autumn dashboard, on the customer detail page.
You should always handle access checks and usage tracking server-side for security. Users can manipulate client-side code using devtools.

Next: Displaying Billing Data Now, whenever your customers change their plan, they will automaticially have the correct access and limits. Next, display billing information to your customers.

Displaying Billing Data

Display plan, balance and usage information to your customers using Autumn’s customer state