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
| Option | Default | Description |
|---|---|---|
| baseUrl | Managed endpoint | Advanced override for self-hosted/proxy relay. |
| refreshIntervalMs | 30000 | Polling interval in milliseconds. |
| startWaitMs | 1500 | Initial wait before degraded-ready mode. |
| bootstrap | undefined | Initial snapshot for fast startup. |
| logger | noop | Custom logger hooks. |
| transport | HTTP transport | Custom 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.