Skip to main content

Overview

The EntitlementsClient provides methods for checking and querying feature entitlements. The check() method is the core primitive of the SDK — it determines whether a customer is allowed to use a specific feature based on their plan.

Methods

check()

Check whether a customer has access to a specific feature. This is the most critical method in the SDK — it evaluates the customer’s plan, metered usage, and custom entitlement overrides.
const result = await revstack.entitlements.check(
  customerId,
  featureId,
  options
);
customerId
string
required
The customer to check.Example: "usr_abc123"
featureId
string
required
The entitlement slug or ID.Example: "api-calls" or "ent_abc123"
options
EntitlementCheckOptions
Optional check parameters.
result
EntitlementCheckResult
The check result.
Example:
const { allowed, reason, remainingBalance } = 
  await revstack.entitlements.check(
    "usr_abc123",
    "api-calls",
    { amount: 10 }
  );

if (!allowed) {
  throw new Error(`Access denied: ${reason}`);
}

console.log(`Remaining: ${remainingBalance} API calls`);

list()

List all active entitlements for a customer, including limits from their plan and any custom overrides.
const entitlements = await revstack.entitlements.list(customerId);
customerId
string
required
The customer whose entitlements to list.Example: "usr_abc123"
entitlements
Entitlement[]
Array of entitlement definitions the customer has access to.
Example:
const entitlements = await revstack.entitlements.list("usr_abc123");

for (const ent of entitlements) {
  console.log(`${ent.name} (${ent.slug}): ${ent.type}`);
}

get()

Retrieve a single entitlement definition by ID.
const entitlement = await revstack.entitlements.get(entitlementId);
entitlementId
string
required
The entitlement’s unique identifier.Example: "ent_abc123"
entitlement
Entitlement
The entitlement definition.
Example:
const entitlement = await revstack.entitlements.get("ent_abc123");
console.log(entitlement.name); // "API Calls"

Common Patterns

Boolean Entitlements

// Check if a feature is enabled
const { allowed } = await revstack.entitlements.check(
  userId,
  "advanced-analytics"
);

if (allowed) {
  // Show advanced analytics dashboard
}

Metered Entitlements

// Check before consuming a metered resource
const { allowed, remainingBalance } = 
  await revstack.entitlements.check(
    userId,
    "ai-tokens",
    { amount: 500 }
  );

if (!allowed) {
  throw new Error("Insufficient tokens");
}

// Proceed with the operation
await openai.chat.completions.create({ ... });

// Report actual usage
await revstack.usage.report({
  customerId: userId,
  featureId: "ai-tokens",
  amount: 500,
});

Usage with API Rate Limiting

import { RateLimitError } from "@revstackhq/node";

async function callAPI(userId: string) {
  try {
    const { allowed } = await revstack.entitlements.check(
      userId,
      "api-calls"
    );
    
    if (!allowed) {
      throw new RateLimitError("API rate limit exceeded");
    }
    
    // Proceed with API call
    return await fetch("https://api.example.com/data");
  } catch (error) {
    if (error instanceof RateLimitError) {
      // Handle rate limit error
      return { error: "Please upgrade your plan" };
    }
    throw error;
  }
}

Build docs developers (and LLMs) love