UsageGate in 5 minutes
UsageGate decides, on every request, what each of your users may do under their plan. You write your plans once. Your server asks UsageGate before each action, and gets a yes or a no.
Three words to know
- Plan
- What you sell, like Free or Pro. Each plan has an id such as
plan_free. - Feature key
- The thing your code asks about, like
ai_credits(a monthly amount) orexport_pdf(on or off). - User id
- Your own user's id. Your users never see or log into UsageGate.
Links marked ↗ open your dashboard.
Get an API key
Create a free account, then generate a key in API keys. Keep it on your server.
.env USAGEGATE_KEY=gk_live_...Set your plans
Open Access rules. Your workspace starts with Free, Starter and Pro, already filled in (Free gets 10
ai_creditsa month). Change the numbers to match your pricing, then Save. More on plans.Install the SDK
lib/gate.ts // npm install @usagegate/sdk import { GateClient } from "@usagegate/sdk"; export const gate = new GateClient(process.env.USAGEGATE_KEY!);Put new users on the free plan
New users have no plan until you give them one. Call this after sign-up. It is safe to call again on every login.
after sign-up await gate.grantPlan(user.id, "plan_free");Check before each action
For something with a monthly amount, spend one unit. If the user has none left, stop and offer an upgrade.
app/api/generate/route.ts const spent = await gate.consume(user.id, "ai_credits", 1); if (!spent.success) { return Response.json({ error: "Upgrade to keep going" }, { status: 402 }); } // ...do the workFor an on/off feature, ask instead of spending:
on/off feature if (!(await gate.canAccess(user.id, "export_pdf"))) { return Response.json({ error: "Pro feature" }, { status: 402 }); }
Other ways to start
- Step-by-step walkthrough, with screenshots of every screen.
- Let an AI agent set it up in Claude Code, Cursor or Codex.
- Start from a working app (Next.js, Supabase, Stripe and UsageGate).

