Feature Flags
Evaluate feature flags locally with the JavaScript SDK. The SDK fetches your flag config with a public key, caches it, and evaluates every check in-process — no network call per isEnabled().
Setup
import { simplrFlags } from "@simplr-ai/js";
await simplrFlags.initialize({
apiKey: "pk_live_xxx", // public key only (pk_*)
environment: "live", // "live" | "test" (default "test")
baseUrl: "https://api.simplr-ai.com", // optional
refreshIntervalMs: 60000, // optional; 0 disables auto-refresh
});
initialize() fetches the config once and starts a background refresh. Call it once at app startup.
Identifying the user
simplrFlags.setUser("user_123");
If you don't set a user, the SDK falls back to the device ID for bucketing, so anonymous users still get stable results.
Checking a flag
if (simplrFlags.isEnabled("new-checkout")) {
// ...
}
// Per-call context for rules or a one-off user:
simplrFlags.isEnabled("new-checkout", {
userId: "user_123",
attributes: { plan: "growth", country: "GB" },
});
isEnabled() returns synchronously and is free — it never hits the network.
API
| Method | Description |
|---|---|
initialize(config) | Fetch config and start auto-refresh. Returns a promise. |
setUser(userId) | Set the default identifier used for bucketing. |
isEnabled(key, ctx?) | Evaluate a flag locally. ctx = { userId?, attributes? }. |
refresh() | Manually re-fetch the config (counts as one billable request). |
getAll() | Return the current cached flag map. |
isReady() | true once the first fetch has completed. |
dispose() | Stop the auto-refresh timer. |
Billing note
Each initialize() and refresh() counts as one flag config request. Local isEnabled() calls are never billed. The first 1,000,000 requests per month are free — see Pricing.