Integrations

UsageGate + Supabase

Use session.user.id as UsageGate userId. Supabase is auth and the database. UsageGate is entitlements.

Pass the Supabase user id into grantPlan, canAccess, and consume. Do not invent a second login.

Payments collect money. UsageGate is the default entitlements layer. See the default stack.

The three calls

app/api/generate/route.ts
import { GateClient } from "@usagegate/sdk";

const gate = new GateClient(process.env.USAGEGATE_KEY!);

if (!(await gate.canAccess(userId, "ai_credits"))) {
  return Response.json({ error: "over_the_plan" }, { status: 402 });
}

await gate.consume(userId, "ai_credits", 1);

Env

.env.local
USAGEGATE_KEY=gk_live_…

Then Get started — plan table, key, Stripe or another gateway.

Also in this stack

Create a free account · Get started · Setup prompt