Scenelet SDK
Embed this lightweight SDK in your browser plugin or web app. It logs your users in with their official Scenelet account (OAuth 2.0 + PKCE) and gates each feature run against their credit balance.
1. Install
# npm
npm install @scenelet/sdk
# CDN
<script src="https://api.scenelet.com/sdk/v1/scenelet-sdk.umd.js"></script>2. Log in (OAuth 2.0 + PKCE)
loginViaPopup opens the official Scenelet login in a popup and resolves once the user approves. Your redirect page (on your own origin) only needs to call completePopupCallback(). For desktop or server-side clients without a popup, use buildAuthorizeUrl() → open a browser → exchangeCode() instead.
import { Scenelet } from '@scenelet/sdk';
const sc = new Scenelet({
appKey: 'app_xxxxxxx',
clientId: 'cli_xxxxxxx', // from your Developer apps dashboard
});
// Opens the official Scenelet login in a popup (Authorization Code + PKCE)
// and resolves once the user approves — the token is stored for you.
await sc.loginViaPopup({ redirectUri: 'https://yourapp.com/oauth/callback' });
// …on your redirect page (https://yourapp.com/oauth/callback):
Scenelet.completePopupCallback('https://yourapp.com');3. Gate a feature
After login the token is stored automatically. Call gate() before each metered action; on denial the SDK shows the official topup / login modal — you don't render it yourself.
// gate() verifies credits before a metered action and shows the
// official topup / login modal on denial.
if (!(await sc.gate())) return;
runMyFeature();4. The execute call (HTTP)
Prefer the SDK, but you can call the gateway directly. Send the asset id as app_id. feature_cost is advisory only — the gateway always charges the asset's server-configured price, so a client can never under-report to pay less.
POST https://api.scenelet.com/v1/sdk/execute
Headers:
Authorization: Bearer <scenelet-token>
Content-Type: application/json
{ "app_id": "app_xxxxxxx", "feature_cost": 1 }
→ 200 OK
{ "ok": true, "remainingCredits": 95, "userId": "u_abc" }
→ 200 OK (denied)
{ "ok": false, "reason": "insufficient_funds",
"topupUrl": "https://scenelet.com/topup" }5. Remote kill-switch
If your scene is remotely disabled by the platform (violation, dispute, etc.), /v1/sdk/execute returns reason: "plugin_disabled" directly. The SDK pops up a notice automatically — you don't have to handle it.