Skip to main content
When you create a plan in Autumn, you define what features your customers on that plan get access to. The check method returns the allowed field in real-time to check if a customer should have access to a feature. You can use this to block access and prompt an upsell.

The allowed field

The allowed field will return true for a given feature if:
  • The customer has an active plan with this feature
  • The customer has an active plan with a credit_system that grants this feature
  • The plan feature is included or prepaid, and the current balance is greater than the required_balance parameter
  • The plan feature is usage-based, and the user has not exceeded their max spend limit
  • The plan feature is unlimited or a boolean feature
Under these conditions, you should allow your customer to use the feature. You can then record the usage event so Autumn can update the allowed field as necessary.

Checking metered features

Before your customer uses a feature, you can check if the customer is allowed to use it and their current usage.
ExampleLet’s imagine you have a free plan for a chatbot that allows 5 messages per month. Before your customer sends an AI message, you can check if they have any left.If they still have messages remaining, they’ll be allowed to send an AI message.
import { useCustomer } from "autumn-js/react";

const { check } = useCustomer();

// check the customer state object locally (no API call)
const { data } = check({ featureId: "messages" });
Even if your product doesn’t have usage limits (ie your feature is purely usage-based), you can still use the above method to prevent usage if a customer’s payment fails.

Checking for a required balance

If you know the balance a user will consume in advance, you can specify it with the required_balance parameter. This means you can prevent a user from starting a process that would consume more than their current balance. By default, required_balance is 1, so not passing this parameter will return allowed: true as long as the customer has a feature balance of 1 or more.
import { useCustomer } from "autumn-js/react";

const { check } = useCustomer();

const { data } = check({ featureId: "messages", requiredBalance: 3 });

Checking and reserving usage

You can check access and record usage in a single, atomic API call using the send_event field. The usage value deducted from the balance will be the required_balance parameter. This is useful for concurrent events.
import { Autumn } from "autumn-js";

const autumn = new Autumn({
  secretKey: process.env.AUTUMN_SECRET_KEY,
});

const { data } = await autumn.check({
  customer_id: "user_or_org_id_from_auth",
  feature_id: "api_calls",
  required_balance: 3,
  send_event: true,
});
If the operation fails, you can then “refund” the usage with a negative usage value in the track endpoint.
import { Autumn } from "autumn-js";

const autumn = new Autumn({
  secretKey: process.env.AUTUMN_SECRET_KEY,
});

const { data } = await autumn.track({
  customer_id: "user_or_org_id_from_auth",
  feature_id: "api_calls",
  value: -3,
});

Checking boolean features

For simple on/off features, use the endpoint to determine if a customer has access. Alternatively you can just check if they have access to a certain plan.
React
const { check } = useCustomer();

// check if the customer has access to a plan
const isPremium = check({ productId: "premium" });

// check if the customer has access to a feature
const dashboardAccess = check({ featureId: "premium-dashboard" });