API reference
SDK methods
Both SDKs read with get(key, …, default). The server SDK takes a context on every call because it holds the rules; the client SDK holds one context, so it takes none.
FeaturekitSDK
import { FeaturekitSDK } from "featurekit-server/sdk";
const flags = new FeaturekitSDK({ sdkKey: process.env.FEATUREKIT_SDK_KEY, baseUrl: "https://flags.acme.com" });
await flags.ready({ timeoutMs: 5_000 });
flags.get("new-checkout", { key: user.id, plan: user.plan }, false);
Option Default What it does
sdkKeyrequired A server key.
baseUrlThe control plane.
mode"streaming"streaming (SSE, falls back to polling), polling, or offline, which never touches the network.
pollIntervalMs30000How often polling mode checks.
bootstrapA snapshot to serve before the first response, for example one committed to your repo.
persist{ kind: "file", path } or any { load(), save() }. Lets a restart during an outage serve the last snapshot.
environmentKeyOnly makes URLs readable in logs: the key already names the environment.
streamReadTimeoutMs3 heartbeats Reconnect after this much silence.
eventson, every 5s { enabled, flushIntervalMs, maxBuckets } for evaluation summaries.
onErrorCalled with background errors. Evaluation never throws.
fetchImplglobal fetch For tests.
Method Returns
get(flagKey, context, defaultValue)The value, typed by the default. Synchronous, in memory.
detail(flagKey, context, defaultValue){ value, variationIndex, reason }, where reason.kind is OFF, TARGET_MATCH, RULE_MATCH, FALLTHROUGH, PREREQUISITE_FAILED, FLAG_NOT_FOUND or ERROR.
ready({ timeoutMs })Resolves once a snapshot is loaded, or at the timeout. Never rejects: serving defaults is a valid state.
on("change", fn)fn({ flagKey }) on every applied change, flagKey: null for a full snapshot. Returns an unsubscribe function.
on("state", fn)fn(state) when state changes. Returns an unsubscribe function.
stateinitializing, connected, reconnecting or offline.
initializedWhether a snapshot is loaded.
close()Stops the stream and flushes summaries.
FeaturekitClient
import { FeaturekitClient } from "featurekit-client";
const flags = new FeaturekitClient({ clientKey: "fk_clt_…", baseUrl: "https://flags.acme.com", context: { key: user.id } });
await flags.ready();
flags.get("new-checkout", false);
Option Default What it does
clientKeyrequired A client or mobile key.
baseUrlrequired The control plane.
contextrequired { key, …attributes }.
streamStream changes over SSE.
contextSignature, contextSignatureExpiresAtFrom your backend, for secure mode .
onSignatureExpiringReturns a fresh { signature, expiresAt } before the old one expires.
bootstrapValues your server rendered, so first paint matches.
onErrorCalled with background errors.
fetchImplglobal fetch For tests.
Method Returns
get(flagKey, defaultValue)The value, or the default when missing or of the wrong type. Synchronous.
detail(flagKey){ value, variationIndex, reason }, or undefined.
allValues()Every value held.
identify(context)Switches to another context. Until it answers, get() returns defaults, never the previous user's values.
ready({ timeoutMs })Resolves on the first values, or at the timeout. Never rejects.
on("change", fn)fn(flagKeys) when values change. Returns an unsubscribe function.
on("state", fn)fn(state): initializing, ready, identifying or offline.
close()Closes the stream.
Previous
Health & metrics
Next
FeaturekitServer