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.
"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/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
| Export | Purpose |
|---|---|
| useFlag(feature) | Boolean enabled state. |
| useEntitlement(feature) | Access view including remaining and paid_through. |
| useRemaining(feature) | Remaining-credit string. |
| useConsumeEntitlement() | Returns consume(feature, amount). |
| FeatureFlagGuard | Renders children or fallback based on feature state. |
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.