SDK API Reference

Core client and hook interfaces used by React and React Native SDK integrations.

Client API

  • `initialize()`
  • `isReady()`
  • `close()`
  • `variation(flagKey, defaultValue, context?)`
  • `evaluate(flagKey, defaultValue, context?)`
  • `on("ready" | "update" | "error", handler)`

Provider API

`FlagProvider` is key-first. `clientKey` is required, while all network/runtime tuning is optional.

  • `clientKey: string` (required)
  • `options?: BetsyClientOptions`
  • `client?: BetsyClient`
  • `singleton?: boolean` (default: `true`)
  • `singletonKey?: string` (default: `clientKey`)

Provider options

OptionDefaultDescription
baseUrlManaged endpointAdvanced override for self-hosted/proxy relay.
refreshIntervalMs30000Polling interval in milliseconds.
startWaitMs1500Initial wait before degraded-ready mode.
bootstrapundefinedInitial snapshot for fast startup.
loggernoopCustom logger hooks.
transportHTTP transportCustom transport implementation.

Hook API

  • `useFeatureFlag(flagKey, defaultValue, context?)`
  • `useFlagsReady()`
  • `useAllFlags(context?)`
  • `useFlagClient()`
  • `useFlagIdentity()` returns `identify`, `clearIdentity`, `getIdentity`

Evaluation context

Context keys should be stable and attributes should be normalized to avoid unintended targeting drift.

TSTypeScript
type EvaluationContext = {
  key?: string;
  anonymous?: boolean;
  attributes?: Record<string, string | number | boolean | null>;
};

type EvaluationReason =
  | "OFF"
  | "TARGET_MATCH"
  | "RULE_MATCH"
  | "FALLTHROUGH"
  | "DEFAULT"
  | "ERROR";

Evaluation result semantics

Result payloads include a reason code and variation ID where available, enabling debuggability and analytics.