SDK Reference

OpenFeature-compatible SDKs for evaluating flags in your application. Flags are evaluated locally from an in-memory cache — no per-evaluation network call.

SDK
Package: @flagr-dev/sdk on npm
Runtime: Node.js ≥ 18
OpenFeature: install @openfeature/server-sdk and use FlagrProvider if you need it

Installation

npm install @flagr-dev/sdk

Quickstart

Create a FlagrClient once at startup — it connects to the SSE stream and keeps a local in-memory cache up to date automatically. Every isEnabled() call is synchronous with no per-evaluation network call.

The SDK key (sdk_live_...) is found in your environment settings inside the dashboard. It grants read-only access to flag states for that environment.
import { FlagrClient } from "@flagr-dev/sdk";

const client = new FlagrClient("sdk_live_...");
client.connect();

const enabled = client.isEnabled(
  "new-checkout",
  "a1b2c3d4-e5f6-7890-abcd-ef1234567890", // tenant_id (optional)
  false                                    // default value
);

if (enabled) {
  // show new checkout
}

Reactive Updates (onChange)

Use FlagrClient directly when you need real-time updates via onChange or want to skip the OpenFeature abstraction. The callback fires immediately with the current value, then again on every SSE update — no new connection is made.

import { FlagrClient } from "@flagr-dev/sdk";

const client = new FlagrClient("sdk_live_...");
client.connect();

const sub = client.onChange(
  "new-checkout",
  "a1b2c3d4-e5f6-7890-abcd-ef1234567890", // tenant_id (optional)
  (enabled) => {
    console.log("new-checkout is now", enabled);
  }
);

// sub.unsubscribe();

Partial Rollout

Flags set to partially_enabled are only truefor tenant/user IDs that appear in the flag's enabled list. Pass the ID via the evaluation context — the SDK resolves it locally, no network call needed.

const enabled = client.isEnabled(
  "beta-rollout",
  req.user.id, // tenant_id (optional)
  false
);