Entitlements
Entitlements define what users can do based on their plan. The SDK evaluates entitlements locally from your Playbook in every mode, and provides React hooks and imperative APIs for access control.
An entitlement answers what an account gets; it is not a permission, which answers what a person may do. Keep your permission checks and add the entitlement check beside them. See Entitlements and permissions.
Entitlement Types
Section titled “Entitlement Types”| Type | Example | Check Pattern |
|---|---|---|
| Feature gate | brand_kit, data_export | Boolean — allowed or denied |
| Usage limit | api_calls, storage_gb | Numeric — current vs. limit |
| Credits | render_credits | Depleting balance |
| Seats | team_members | Per-account count limit |
| Capability tier | analytics_tier | Plan-level access (starter → pro → enterprise) |
Checking Entitlements
Section titled “Checking Entitlements”One rule, every surface. The verdict is allowed on an EntitlementResult — rt.can(), useEntitlement().result, the server re-check — and can on the useCan hook, which is resolved && !denied and so also covers the moment before the first answer arrives. status is the shape of the answer, never the verdict: limited appears on both sides of allowed.
React Hook — useCan
Section titled “React Hook — useCan”The simplest reactive check. useCan(handle) returns { can, limited, result }. can is the verdict: resolved && !denied, where denied means status === 'denied' || allowed === false. A limited result that still grants (allowed: true) keeps can true; a limited result that denies is a deny. Gate on !can — it folds in “not yet resolved”, which result.allowed alone cannot:
import { useCan } from "@revturbine/sdk";import { DemoApp } from "./DemoApp";
function ExportButton() { const { can, limited } = useCan("data_export"); if (!can) return <button disabled>Upgrade to Export</button>; return <button>Export Video{limited ? " — running low" : ""}</button>;}
// Dan is not entitled to data_export, so `can` is false and the button is// disabled. Switch to user="user_alice" (entitled) and it enables.export default function App() { return ( <DemoApp user="user_dan"> <ExportButton /> </DemoApp> );}Opens a live, editable sandbox with the published SDK.
Full surface — useEntitlement
Section titled “Full surface — useEntitlement”For the complete reactive result (allowed / denied / limited / isLoading / error / gatedPlacement / recheck), use useEntitlement:
import { useEntitlement } from '@revturbine/sdk';
function ExportButton() { const { allowed, denied, isLoading } = useEntitlement({ handle: 'data_export', });
if (isLoading) return <button disabled>Loading…</button>; if (denied) return <button disabled>Upgrade to Export</button>;
return <button>Export Video</button>;}Declarative gate — <Gate>
Section titled “Declarative gate — <Gate>”<Gate> gates its children declaratively. can="handle" checks an entitlement (shorthand for check={{ entitlement: 'handle' }}); children render while entitled, and a configured upgrade placement — or deniedFallback — shows on denial. limitedFallback renders a soft “running low” state while access is still granted:
import { Gate } from "@revturbine/sdk";import { DemoApp } from "./DemoApp";
// Dan lacks data_export, so the gate renders the configured upgrade placement// in place of the children. Switch to user="user_alice" to see the children.export default function App() { return ( <DemoApp user="user_dan"> <Gate id="editor_export_action" surfaceTemplateIds={["modal_overlay"]} can="data_export" > <button>Export Video</button> </Gate> </DemoApp> );}Opens a live, editable sandbox with the published SDK.
A <Gate> is also a placement. On denial the gate doesn’t render hardcoded UI — it resolves a placement from your monetization config and renders it in place of the children. So what a denied user sees — the upgrade modal or banner, its headline, offer, and CTA — is authored in the dashboard (or the CLI config), not baked into your app. Your PM, growth, or marketing team can rewrite the denial copy, swap the offer, or A/B-test it with no code deploy. surfaceTemplateIds scopes which surface templates can fill the gate; deniedFallback is the static backstop shown only when no placement is configured for it.
Live gate example
Section titled “Live gate example”Switch demo users to see the gate respond — it runs in local_only mode with no backend. Two more gate scenarios are on the Interactive Playground: Branding gate and Brand Kit gate.
Data Export gate — a blocking modal gate on a paid feature.
import { Gate } from "@revturbine/sdk";
export function Example() { return ( <Gate id="editor_export_action" surfaceTemplateIds={["modal_overlay"]} check={{ entitlement: "data_export" }} > <div style={{ padding: 16, background: "#e8f5e9", borderRadius: 8, border: "1px solid #a5d6a7" }}> ✅ Access granted — premium content visible </div> </Gate> );}With Auto-Gate
Section titled “With Auto-Gate”When autoGate: true, the hook automatically resolves an upgrade placement if the entitlement is denied:
const { allowed, denied, gatedPlacement } = useEntitlement({ handle: 'data_export', autoGate: true, gatePlacementRequest: { slotId: 'export_gate', componentType: 'modal', },});
if (denied && gatedPlacement) { // Render gatedPlacement.content as an upgrade prompt}Imperative API
Section titled “Imperative API”Pass only what your app knows better than the Playbook — current consumption, or the tier a feature needs. Everything else comes from plan configuration.
| Entitlement type | Second argument | Result includes |
|---|---|---|
| Feature | — | status, allowed |
| Capability tier | { requiredTier } | status, allowed, current_tier |
| Usage limit | { used } | status, allowed, limit, used, remaining |
| Credits | { balance } (the remaining credits; exhausted at 0 or below; wins over used) | status, allowed, remaining |
| Seats | — (counts come from the usage snapshot) | status, allowed |
const result = await sdk.can('data_export');
// result.status: 'allowed' | 'limited' | 'denied'// result.allowed: boolean// result.reason: string (optional)// result.current_tier: string (optional, for tier-based)// result.limit / used / remaining: present when a usage_limit or credits rule matchedEntitlement Result
Section titled “Entitlement Result”Every entitlement check returns an EntitlementResult:
interface EntitlementResult { status: 'allowed' | 'limited' | 'denied'; allowed: boolean; reason?: string; current_tier?: string; limit?: number; // effective limit from the matched rule used?: number; // amount the evaluation applied against limit remaining?: number; // max(0, limit - used)}// limit / used / remaining appear only on limit-bearing outcomes — a matched// usage_limit or credits rule. Their absence means the check was// limit-agnostic (a feature or tier rule), not unlimited. For balances across// handles, use useUsageSnapshot() (see "Reading Usage" below).| Status | Meaning |
|---|---|
allowed | Full access — proceed normally |
limited | At or past a limit. Read allowed, not this — under the default (unset) enforcement limited carries allowed: false; only degrade and allow_overage pair it with allowed: true. There is no “approaching” state. |
denied | No access — show upgrade prompt or block |
Usage Tracking
Section titled “Usage Tracking”Report usage to keep entitlement checks accurate:
// Update current balancessdk.update({ usage: { api_calls: 950, storage_gb: 45, team_members: 5, },});update() triggers:
- Re-evaluation of usage-based entitlements
- Segment re-evaluation (targeting rules may change)
- Decision cache invalidation
- Local runtime state persistence
update() accepts a widened session-context patch, so the same call can also
refresh plan, traits, or page context. Usage balances always belong under the
usage key; a bare entitlement handle is not interpreted as usage.
Generate Entitlement Handle Types
Section titled “Generate Entitlement Handle Types”Generate a union from your Playbook so can() accepts only handles that exist:
npx revturbine generate types ./revturbine.playbook.json --out src/revturbine.generated.tsimport { Entitlements } from './revturbine.generated';
// The generated value retains its EntitlementHandle literal type.const handle = Entitlements.feature.data_export;const result = await sdk.can(handle);See the CLI reference for selectors and all supported generated type families.
Reading Usage
Section titled “Reading Usage”import { useUsageSnapshot } from '@revturbine/sdk';
function UsagePanel() { const { usage, refresh } = useUsageSnapshot();
return ( <ul> {Object.entries(usage).map(([handle, data]) => ( <li key={handle}> {handle}: {data.current} / {data.limit ?? '∞'} </li> ))} </ul> );}Patterns by Entitlement Type
Section titled “Patterns by Entitlement Type”Feature Gate
Section titled “Feature Gate”const { allowed } = useEntitlement({ handle: 'brand_kit' });// allowed: true/falseUsage Limit
Section titled “Usage Limit”const { allowed, limited, result } = useEntitlement({ handle: 'api_calls' });// limited: at or past the limit — read `allowed` for the verdict// result.used / result.limit / result.remaining: on the result for this checkCredits
Section titled “Credits”const { limited, result } = useEntitlement({ handle: 'render_credits' });// result.status / result.allowed reflect access as credits run low// result.remaining: the balance the evaluation usedCredit grants and credit packs
Section titled “Credit grants and credit packs”A credits rule grants credits in two ways, and can use both:
allowance_valueis a recurring allowance: the credits each reset period (set byreset_period) starts with.one_time_grantis granted once. On a plan, the customer gets it when they first enter the plan (a signup bonus). On a one-time add-on, such as a credit pack, it is what one purchase adds.
one_time_grant was called initial_grant before. The old name is still read, with warning VAL-ENT-04; rename it when you next edit the Playbook.
A credit pack is an add-on with its own credits rule: no reset period, no allowance, and the pack size in one_time_grant. One add-on can sell the pack in several sizes, one Public variation per size, each sized by its own rule’s grant. A checkout button for such a pack must name the variation of the size it sells ("purchase": "<variation handle>"). Naming the add-on itself fails launch with VAL-PLC-16, because RevTurbine can’t tell which size you mean.
const { denied, result } = useEntitlement({ handle: 'team_members' });if (denied) { // seat counts: read from useUsageSnapshot() (see "Reading Usage") // Show "seat limit reached" prompt}Capability Tier
Section titled “Capability Tier”const { denied, result } = useEntitlement({ handle: 'advanced_analytics' });if (denied) { // result.current_tier: 'professional' // Show "upgrade to Professional" prompt}Fail-Closed Semantics
Section titled “Fail-Closed Semantics”A check grants access only when it can affirmatively justify the grant; every other outcome denies, with allowed: false and a reason naming why. That is what fail-closed means wherever these docs use it — and it is about the answer, not the network: the Playbook is cached locally, so a configured runtime answers without a round trip, and the no-rule cases below are the only ones where there was nothing to evaluate. The reason lets you tell those apart from a real denial:
// Connected mode, the launched Playbook could not be fetched:// { status: 'denied', allowed: false, reason: 'config_unavailable' }
// Local mode, no Playbook and no cached result:// { status: 'denied', allowed: false, reason: 'entitlement_not_in_playbook' }
// A real denial — a rule decided this:// { status: 'denied', allowed: false, reason: 'no_matching_entitlement_rule' }See Entitlement reason codes for the complete emitted set.
Parameter entitlements
Section titled “Parameter entitlements”price_per_unit and rate_limit configure application behavior; they are not
always-allowed feature gates. can() returns allowed: false, status: 'denied',
and reason: 'not_access_entitlement_kind' for these kinds. Do not reinterpret
that denial as a grant or use a parameter handle in Gate.
Use a separate access entitlement for authorization. The application reads
parameter metadata from its admitted Playbook/provider data and implements the
meter or rate limiter itself. Resolve the appropriate rule for the current
plan/target; do not simply take the first rule or infer unlimited access from an
absent value. Display tokens can expose metadata for presentation, but a display
token is not enforcement. This version does not provide a new universal
getParameter() or getRateLimit() API.
For example, inspect the configured rules through the initialized SDK’s
session.sdk.getPlaybook() accessor. This lists metadata for a handle; it deliberately
does not select an effective rule for a particular user:
import { initRevTurbine } from '@revturbine/sdk';
function inspectParameterRules( session: Awaited<ReturnType<typeof initRevTurbine>>, entitlementHandle: string,) { const playbook = session.sdk.getPlaybook(); if (!playbook) throw new Error('No admitted Playbook is available'); return playbook.entitlement_rules .filter((rule) => rule.entitlement_id === entitlementHandle) .map((rule) => ({ targets: rule.targets, segment_ids: rule.segment_ids, rate_value: rule.rate_value, period_scope: rule.period_scope, amount_cents: rule.amount_cents, currency: rule.currency, }));}Keep absent values absent. A rate value needs its period, and a price needs its currency; do not treat either as an access grant. Use this inspection for configuration/debugging or presentation. Application-owned enforcement must apply the intended plan, add-on, and segment policy rather than taking the first row returned here. If the admitted artifact does not include this metadata, use your application’s authoritative configuration source instead of inventing a default.
A mirrored grant is a boolean or a record of optional status, allowed,
limit, used, remaining and reason (0.16.0: the TypeScript type now
accepts exactly that shape; it no longer asks for entitlement_id or
entitlement_handle).
For mirrored access grants, UserContext.entitlements and entitlementMerge
control how application facts combine with Playbook evaluation. The default
gives application mirrors precedence. A result with entitlement_mirrored
therefore need not have a Playbook rule_handle. See
SDK upgrades before copying old rule-only assertions.
Per-call cost
Section titled “Per-call cost”On a usage-limit or credits entitlement, say what this call would consume:
const result = await rt.can('ai_generations', { cost: 3 });<Gate id="ai_generations_gate" can="ai_generations" cost={3} deniedFallback={<UpgradePrompt />}> <GenerateButton /></Gate>
const { can } = useCan('ai_generations', { cost: 3 }); // also useEntitlement({ handle, cost })cost belongs to the call. It is not a Playbook field. In Python it is context={"cost": 3} on can / check_entitlement, and in Rust a cost key in the context passed to the check.
cost | What happens |
|---|---|
above 0 | allowed while it fits: a usage limit counts up (usage + cost <= limit), credits count down (cost <= balance). Over follows the rule’s enforcement mode (hard_block, degrade, allow_overage). Fractional costs are valid, with a small tolerance for binary floating-point error. See Credits count down, usage limits count up for where the numbers come from |
0 | always allowed, even past the limit (the action is free). A developer warning (entitlement_cost_zero) makes sure that was deliberate |
| left out | today’s check: allowed while usage < limit. A developer error (entitlement_cost_missing) tells you to pass a cost: use 0 for a free action |
negative, not a number, NaN, infinite | treated as left out, with the error entitlement_cost_invalid naming only the kind of the bad value, never the value |
Other entitlement kinds, and unlimited entitlements, ignore cost without a message.
The result carries the diagnostic as result.diagnostic ({ level, code, handle, received? }). It never changes allowed, status or reason, and it appears only on a single-handle check, never on a bulk read of every entitlement. Each handle and code is reported once per process: console.warn / console.error in the browser, console.error and a RuntimeWarning on the revturbine logger in Python, one line on stderr in Rust. Nothing is thrown or panicked.
Every existing check on a usage-limit or credits entitlement now logs the missing-cost error once until you pass a cost. The decision is unchanged.
Credits count down, usage limits count up
Section titled “Credits count down, usage limits count up”With a cost above 0, the direction follows the kind of the Playbook rule. There is no prop for it on <Gate>, the hooks or the functions: you pass the same cost as before.
- A credits entitlement counts down. The check is over when the cost exceeds the balance.
- A usage limit counts up. The check is over when
used + costexceeds the limit.
The SDK never decrements a balance. It compares what it is given; your app (or the RevTurbine backend) owns the number and reports the new one.
Where the numbers come from. An app that mirrors its own entitlements (user.entitlements, identify, update or setUserContext) reports a record such as { status: 'allowed', limit: 1000, used: 995 }. The first source that has a number wins:
| Kind | Sources, in order |
|---|---|
| credits | the call’s balance; the call’s used against the rule’s allowance; the app’s remaining, or limit - used when it sent both; the usage the SDK holds |
| usage limit | the call’s used against the rule’s limit; the app’s used and limit (a missing half falls back to the held usage or the rule’s limit); the usage the SDK holds |
On a usage limit the app’s remaining on its own, and a per-call balance, are ignored. A finite limit the app reports applies even when the rule is unlimited. When the app sends both limit and used for credits, the pair is compared as used + cost <= limit, so limit: 1000, used: 999.7 accepts a cost of 0.3 exactly. An explicit remaining is compared as a balance. If your entitlementMerge makes limit or used follow the Playbook instead of the app, that pair is no longer the app’s and the balance form (limit - used) is used.
When the cost does not fit the check is the rule’s own over result: its enforcement mode (hard_block, block_with_upsell, degrade, allow_overage), its existing reason (for example credit_balance_exhausted_block_with_upsell or usage_limit_reached) and its rule_handle. A <Gate> then renders its gate placement, or deniedFallback, instead of its children. With no rule, or no plan, for the entitlement, and the app having said “allowed”, the result is status: 'limited', allowed: false, the plain reason (credit_balance_exhausted or usage_limit_reached) and no rule_handle.
Cost 0, a missing cost and an invalid cost behave exactly as before. They never consult the app’s numbers.
What changes for integrations that mirror entitlements
Section titled “What changes for integrations that mirror entitlements”- A mirrored “allowed” no longer overrides an over result when the numbers compared were the app’s or the call’s. Before, an app that reported
{ status: 'allowed', limit: 1000, used: 995 }was allowed for a cost of 500. A mirrored “denied” still wins, and a mirrored answer with no numbers (true,{ status: 'allowed' }) is unchanged. - A mirrored record with a boolean
allowedand nostatusnow sets the answer.{ allowed: true }isallowedand{ allowed: false }isdenied, with the reasonentitlement_mirroredand norule_handle. Before, theallowedflag of such a record was ignored.
Python and Rust give the same results as the browser for every case above (the parity corpus holds them byte-identical).
One entitlement per Gate
Section titled “One entitlement per Gate”A <Gate> checks one entitlement (from can or from check); usage thresholds can be combined with it. To require two entitlements, nest two Gates, so each shows its own upgrade message:
<Gate id="export-gate" can="export" deniedFallback={<UpgradeToExport />}> <Gate id="export-quota" can="export_quota" cost={1} deniedFallback={<OutOfExports />}> <ExportButton /> </Gate></Gate>A Gate given more than one entitlement check is a developer error: it fails closed (it renders as denied) and logs one console.error naming the Gate id and the count. Before 0.16.0 the second entitlement was silently ignored.
Next Steps
Section titled “Next Steps”- Placements Guide — render upgrade prompts for denied entitlements
- Events & Analytics — track entitlement check outcomes
- Error Handling — fail-closed checks and recovery patterns
- Try it live → Data Export Gate