Skip to content
Platform documentation
React SDK
SDKs

React SDK

Add feature gates and customer access to your interface.

Wrap your application

Use a provider publishable key for public plan listings and a short-lived holder-scoped token for private customer reads and mutations. Generate the token on your backend after authenticating the customer.

tsx
"use client";

import { BagsevenProvider, FeatureFlagGuard } from "@bagseven/sdk/react";

export function CustomerApp({ accessToken }: { accessToken: string }) {
  return (
    <BagsevenProvider
      publishableKey={process.env.NEXT_PUBLIC_BAGSEVEN_PUBLISHABLE_KEY!}
      apiUrl="/api/public"
      holder="customer-123"
      accessToken={accessToken}
    >
      <FeatureFlagGuard feature="ocr" fallback={<p>Purchase access first.</p>}>
        <p>OCR access is active.</p>
      </FeatureFlagGuard>
    </BagsevenProvider>
  );
}
API routing

/api/public is the console’s public API proxy. In your own app, provide a suitable proxy or configured API base and CORS policy. A publishable key alone cannot read private customer access or consume credits.

Read access and consume credits

ExportPurpose
useFlag(feature)Boolean enabled state.
useEntitlement(feature)Access view including remaining and paid_through.
useRemaining(feature)Remaining-credit string.
useConsumeEntitlement()Returns consume(feature, amount).
FeatureFlagGuardRenders children or fallback based on feature state.
tsx
import { useConsumeEntitlement, useRemaining } from "@bagseven/sdk/react";

export function UsageButton() {
  const remaining = useRemaining("ocr");
  const { consume } = useConsumeEntitlement();
  return (
    <button onClick={() => void consume("ocr", "1")}>
      Use a credit · {remaining} remaining
    </button>
  );
}

The hook is useful for customer interactions. For retry-sensitive metered backend jobs, use the Node client with a stable job-specific idempotency key.

Enforce access on the server

A browser gate controls presentation. Check and consume authoritatively on the backend before protected work. Never place a secret API key, daemon token, or private wallet key in a React prop or NEXT_PUBLIC environment variable.

Bagseven documentationemail and wallet · Avalanche · Registry