Build
Define access rules
Rules answer one question: what can this user do, and how much? You design them once. Your app never hard-codes plan names or credit amounts — it only asks about feature keys.
The three pieces
Plan
A commercial package: Free, Pro, Team. Tie paid plans to your Stripe Price id.
Feature
Something you gate. The featureKey (e.g. ai_credits) is what the SDK asks about.
Limit
How much of that feature the plan includes (amount + type: boolean, numeric, or metered).
Build it in the dashboard
- Open Access rules.
- Add a plan node (e.g. Free / Pro). Set the Stripe Price id on paid plans.
- Add a feature node with a stable key like
ai_credits— engineers will use this string forever. - Add a limit node with an amount (e.g. 1000) and type (METERED / NUMERIC_LIMIT / BOOLEAN).
- Connect edges: Plan → Feature (“includes”), Feature → Limit. Save.
Tip: pick boring, stable feature keys. Renaming a key later means updating every canAccess call in your product.
Same graph via API / SDK
The dashboard saves a nodes + edges graph. You can create the same shape from a setup script:
await gate.putRules({
nodes: [
{ id: "plan_free", kind: "plan", label: "Free", x: 40, y: 80 },
{
id: "feat_ai",
kind: "feature",
label: "AI credits",
featureKey: "ai_credits",
featureType: "METERED",
x: 280,
y: 80,
},
{
id: "lim_1k",
kind: "limit",
label: "1,000 / month",
amount: 1000,
featureType: "METERED",
x: 520,
y: 80,
},
],
edges: [
{ id: "e1", from: "plan_free", to: "feat_ai", label: "includes" },
{ id: "e2", from: "feat_ai", to: "lim_1k", label: "Free" },
],
});After rules exist
- Create an API key
- Call
canAccess/consumewith the same feature key — see Add the SDK - Connect Stripe so paid invoices refill balances and set the period end — see billing periods
Need help drafting rules?
Paste the ready-made prompt on the AI coding agent page into Cursor or Claude — it walks through plans, keys, and first gate calls with you.
